{{announcement.body}}
{{announcement.title}}

Ant-to-Maven Conversions: The Painless Method

DZone 's Guide to

Ant-to-Maven Conversions: The Painless Method

You no longer need to sweat it over Ant-to-Maven conversions. We've got you covered.

· Java Zone ·
Free Resource

If 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

  1. Declare the groupId, arifactId, and version 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.

  1. If you are on Windows, download the File Checksum Integrity Verifier utility from Microsoft's site.
  2. Execute the following from command line to generate a SHA1 signature for the jar file we need to find.
  3. For a single jar file:
    checksum generation with fciv toolAbove, we have checksum generation using the FCIV tool.
  4. For a directory of jars, go to Nexus repository manager and click Advanced search
    Nexus repository manager
    Search Nexus repository using the generated checksum value
  5. 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.

Topics:
java ,maven ,dependency management ,ant ,conversions

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}