wood burning stoves*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 9345
    
    2

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, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    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: 9345
    
    2

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: 15959
    
  19

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: 9345
    
    2

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: 5812
    
    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.
Shiv Vishwakarma
Greenhorn

Joined: May 29, 2007
Posts: 21

Hi,

There is a similar situation for me, where in I have to migrate an existing enterprise application to maven.
I did everything like created a parent maven project with packaging as POM.
then i created ear project which is again dependent on war, ejb and utility java project and I have declared all the jars as dependency in parent POM.xml and application is building properly when i execute the maven install command...but when I deploy this ear onto websphere it gives me error and it is not able to find the jars.
I was able to find the cause the entries of jar references was missing in MANIFEST file.
I believe ideally manifest file should be generated when ejb jar is created...but somehow it is not working...
I almost tried every other command but it is not working...I know I can write my own manifest file but it is generated by maven.
Please correct if I am wrong...and suggest me a solution.

Thanks,
Shiv


Vishwakarma, Shiv
SCJP 1.4, SCWCD 5
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

If you just have one project, just recreate it in Maven. If you have a lot and they work the same way, it might be worth partially automating YOUR Ant build to Maven. We were able to do that with our projects because there was a lot of commonality


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant to Maven Converter
 
Similar Threads
Maven or Ant?
How to mavenize a project
Why Maven?
Maven: What's the big deal?
ant vs. maven