Install maven
- Install maven e.g. http://smileybits.blogspot.com/2013/09/installing-maven-304.html
- Install a maven repository manager e.g. http://smileybits.blogspot.com/2013/09/installing-sonatype-nexus-open-source.html
Learn about maven
Look up some maven tutorials and documentation e.g.
- https://maven.apache.org/guides/
- https://maven.apache.org/ref/3.0.5/maven-model/maven.html
- http://books.sonatype.com/mvnex-book/reference/public-book.html
- http://books.sonatype.com/mvnref-book/reference/index.html
- https://today.java.net/pub/a/today/2007/03/01/building-web-applications-with-maven-2.html
- http://www.mkyong.com/maven/how-to-convert-java-web-project-to-maven-project/
- http://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
- http://books.sonatype.com/mvnex-book/reference/web.html
- https://devcenter.heroku.com/articles/local-maven-dependencies
- http://docs.codehaus.org/display/MAVENUSER/Maven+Repository+Manager+Feature+Matrix
- http://mestachs.wordpress.com/2012/05/17/maven-best-practices/
- http://docs.codehaus.org/display/MAVENUSER/Multi-modules+projects
- http://blog.sonatype.com/people/2010/08/how-to-migrate-from-ant-to-maven-project-structure/
Reorganise source files
- Create a skeleton maven directory structure for your code using an appropriate maven archetype command e.g run commands similar to the following on the command line.
For a war
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=com.mycompany -DartifactId=mywebapp
For a jar
mvn archetype:create -DgroupId=com.mycompany -DartifactId=myjar
- Copy java source files directories from the ant project to the appropriate maven structure location e.g. C:\maven-migration\mywar\src\main\java\
- Copy non-java files that are in the classes directory to the appropriate maven structure location e.g. C:\maven-migration\mywar\src\main\resources
- Copy other web resources (everything else that is not within the classes directory) to the appropriate maven structure location e.g. C:\maven-migration\mywar\src\main\webapp
- Delete the WEB-INF\lib directory under the maven webapp directory, if that was the location of libraries.
Create dependencies for libraries
- From the ant project’s WEB-INF\lib directory, go through the libraries one at a time, determining if the library is used directly by your code. If so, add a dependency for the library to your maven project’s pom file. Use a maven central search website to determine dependency details like artefact id etc. e.g. http://www.maven-repository.com/. Mark or identify these as resolved e.g. on a piece of paper listing all the libraries.
- Next, go through the remaining libraries and figure out which libraries are a dependency of one of the libraries already added. You may need to review the poms of the added libraries. You can see the library poms from the maven central search website. An IDE can also help to identify indirect dependencies e.g. Eclipse has a Dependency Hierarchy feature that shows these. Mark the indirect dependencies you’ve identified as resolved.
- From the remaining libraries, identify those which are not used by your code directly but are required at runtime or for testing. Add these dependencies to your maven project pom with a runtime or test scope as appropriate. Mark these dependencies and the indirect dependencies that they bring, as resolved.
- You’ll likely be left with non-maven libraries that aren’t built using maven or which aren’t available on a public maven repository. You’ll need to download packages for these libraries and see if they contain an indication of the libraries that they depend on. You’ll then need to create a pom for these libraries and deploy them to some maven repository e.g. an in-project one, see https://devcenter.heroku.com/articles/local-maven-dependencies
- Once you have all the libraries matched, refine the dependencies in your pom e.g. to define exclusions for indirect dependencies that you don’t use. You can also override versions of libraries included.
- Define other aspects of the pom similar to what is found in your ant project’s build.xml file e.g. configuration of the maven-compiler-plugin to generate java 1.6 compatible classes