aspose file tools*
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant to Maven Converter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant to Maven Converter" Watch "Ant to Maven Converter" New topic
Author

Ant to Maven Converter

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Guys,

Is there a tool that would convert an Ant based enterprise project to a Maven project? I just googled and did not find anything satisfactory. I was just thinking why not go about building one. What do you guys think?


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5776
    
    7

No tool that I know of. I usually:
1) Create a blank Maven project using an appropriate archetype.
2) Manually move the source files from my old Ant project to the Maven directory structure
3) Add the JAR dependencies to the pom.xml
4) There are usually odds-and-ands files that don't seem to fit that I then have to decide where to place. For example, where does the readme.txt file go? After looking at the Maven Assembly Plugin and figuring out how to use that to package my app, I finally decided that readme.txt goes into src/main/docs. As another example, one app contains a CHM file which we got from the documentation team. I decided that the CHM was actually a binary resource and fit better within the repository where it could be included by the assembly plugin in the packaging. Anyway, exactly how you handle these extra files is really up to you.

I have spent the better part of the last two months helping various teams decide how to migrate their projects to Maven and most of my time has been spent in step 4.


JBoss In Action
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

From my initial impression on this, I guess the challenging part would be to identify the dependencies from the ant build.xml file. I see that there are numerous ways trhat a project can define the dependent external jars in the build.xml. So need to nail on that one before I get started.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

You're welcome to try, but the hardest part on automated conversion is the fact that Ant is a very broad, unstructured system and it would be akin to disassembling a custom program and trying to fit all of the logic twists and turns into a simpler, more structured output. Dependency determinate would actually be one of the less difficult tasks, I think.


Customer surveys are for companies who didn't pay proper attention to begin with.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

I have mostly figured out the pseudo steps that I would need to do to get this thing working. In my steps I was really concerned on how I will extract the dependant jars from the build.xml file. The rest I feel should not be much complicated.

As per my thoughts, Ant has many different ways to specify the inclusion of dependent jars and I have to make my program suitable enough to walk through those different ways and try to get the dependency tree out of it. What else do you think should be difficult here other than this?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5776
    
    7

A good tool to use for identifying the dependencies is JBoss Tattletale. It generates reports about all of the JAR files in a directory (and subdirectories) listing dependencies among the JARs.

To use it, first do the Ant build. Then take the resulting JARs and classes and combine into the same directory with the JARS that Ant used to do the build. Then run Tattletale against that directory. Then look in the reports for the immediate dependencies on your generated classes or JARs. That will give you the dependencies to add to the pom.

Of course, the alternative is to run the maven build and see what classes it can't find and add the JARS for those classes as dependencies

It has been my experience that Ant builds usually include way more JAR files in the <javac> classpath that what it really required. After all, it is so easy to simply point to a directory with dozens of JARs and use **/* to include them all. That requires very little effort and results in no missing classes, so why not? But with Maven it is better to have only the bare minimum set of dependencies, and let is transitive dependency mechanism do the rest.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant to Maven Converter
 
Similar Threads
Why Maven?
How to mavenize a project
Maven: What's the big deal?
ant vs. maven
Maven or Ant?