How I migrated a legacy project from Ant to Maven
This is about a legacy project which I recently was assigned to. I was asked to migrate its building process from Ant to Maven.
After all, it was less difficult than I thought at first glance. I did a very little research and obtained some ideas from here. Let’s see.
1. Create a maven project.
I used the archetype for web projects:
mvn archetype:generate -DgroupId={project-packaging}
-DartifactId={project-name}
-DarchetypeArtifactId=maven-archetype-webapp
-DinteractiveMode=false
2. Migrate dependencies.
Then, (apparently) the most difficult part: guessing the maven coordinates for a pile of jars with no version! Fortunately, I found an easy way to do it: using the checksum search in Nexus at repository.sonatype.org.
a. Checksum tool.
In my case, I chose FCIV utility for Windows. I downloaded the exe file and placed it in C:\Windows\System32 (ready to be used from any path).
b. Generate jar checksum.
I iterated over all external dependencies (also to check if jars with versions have the correct one). For example, for spring-core.jar:
i. I ran on a Windows command console at the containing folder:
fciv spring-core.jar -sha1
and got 3a4bf426a3d8dc0766a3a9c70a33f6c3ac8db144.
ii. I searched using that checksum at Sonatype RSO and got 2.5.6.SEC02 version for spring-core artifact.
iii. I copied Maven dependency and pasted in my pom.xml.
c. Unknown dependencies.
There were few dependencies which I couldn’t resolve. So I created a local repository in my pom.xml:
<repositories>
<repository>
<id>local-repo</id>
<url>file://${basedir}/local-repo</url>
</repository>
</repositories>
and installed those original jars there, using:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<myGroup> \
-DartifactId=<myArtifactId> -Dversion=<myVersion> \
-Dpackaging=<myPackaging> -DlocalRepositoryPath=<path>
See more at “Adding a custom jar as a maven dependency”.
3. Moving source files.
Finally, I moved source files under src/main/java default path, and the web content into webapp folder.
That was all, and it worked out on the first try!