General Guidelines on Mavenizing an Existing Eclipse project
- Create an empty Maven project of the same type as your original project (i.e. jar, war…) using the appropriate archetype.
- cd into the project directory that you just created and which now has a pom.xml file for your project.
- Run mvn eclipse:eclipse -DdownloadSources=true in this directory.
- Import the Maven project into Eclipse
- Move the original project’s source code and resources into the new Maven project structure.
- Get all your classpath dependencies into your pom.xml
Note, that unlike Eclipse, Maven has the concept of test scope for those dependencies that are required for testing, but not by the application itself. For example, for JUnit you would typically add a dependency like:
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency>
If you do have an Ant build file, it may help you determine which artifacts are only required for tests.
- Clean up your Mavenized project. For example, you don’t need your lib directory and Ant’s build xml anymore.
- Make Maven happy. Suggested test:
- Delete you local maven repository
- Open a shell or command prompt and go where your project’s pom.xml is.
- Run mvn clean install
- Check if your local repo is back with your project and all the dependencies.
- Make your Eclipse happy. If it isn’t:
- Ensure that your M2_REPO variable is properly defined (this needs to be done once per workspace). If not, you can set this via the command:
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo