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!
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.
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.
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.
An IDE is no substitute for an Intelligent Developer.
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?
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.
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.
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