Ant-to-Maven Conversions: The Painless Method
You no longer need to sweat it over Ant-to-Maven conversions. We've got you covered.
Join the DZone community and get the full member experience.
Join For FreeIf you've ever come across a situation to convert your grandfathers' Java project (which he used to build with Ant) to Maven, you know my pain. Maybe you are reading this because it's time to do that. So, here is a definitive guide to doing that without getting lost in dependency hell (RIP grandpa)!
Create the Directory Structure
Execute the following commands in order to create the standard Maven directory structure.
For Web Apps
mvn archetype:generate -DgroupId={project-packaging} \
-DartifactId={project-name} \
-DarchetypeArtifactId=maven-archetype-webapp \
-DinteractiveMode=false
For Standalone Apps
mvn archetype:generate -DarchetypeGroupId={project-packaging} \
-DarchetypeArtifactId=={project-name} \
-DarchetypeVersion=1.4
Declare Dependencies
- Declare the
groupId
,arifactId
, andversion
for the project
<project>
<modelVersion> 4.0.0 </modelVersion>
<groupId> com.mycompany.app </groupId>
<artifactId> my-app </artifactId>
<version> 1.0.1 </version>
</project>
<project>
<modelVersion> 4.0.0 </modelVersion>
<groupId> com.mycompany.app </groupId>
<artifactId> my-app </artifactId>
<version> 1.0.1 </version>
</project>
2. Find the dependencies for each jar file linked to the project.
- Jars having pom.xml files inside - Extract the from the pom file.
- Jars not having a pom.xml file - Refer to the signature-based artifact search method explained below.
- Jars which cannot find using the above 2 methods - Install to your local maven repository or your companies artifact repository.
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<myGroup> \
-DartifactId=<myArtifactId> -Dversion=<myVersion> \
-Dpackaging=jar
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<myGroup> \
-DartifactId=<myArtifactId> -Dversion=<myVersion> \
-Dpackaging=jar
Signature-Based Artifact Search
Now, we have come into the best part.
- If you are on Windows, download the File Checksum Integrity Verifier utility from Microsoft's site.
- Execute the following from command line to generate a SHA1 signature for the jar file we need to find.
- For a single jar file:
- For a directory of jars, go to Nexus repository manager and click Advanced search
- Find the matching artifact details using the SHA1 hash obtained from the above step.
Now, you should be able to find all the dependency information referred from old Ant project in this way. So go ahead and get your hands dirty.
Published at DZone with permission of Dinusha Nirmal. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments