Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert existing project to a maven project

Tags:

java

maven

When I started my project, I wasn't aware of Maven.. I realized the importance of it after the project had already grown to a pretty large size. At that time I was really into rapid development, hence I didn't really want to break the flow. So, I deferred plugging maven into the project. Now I have a little breathing space, so I'd like to add maven into the project.

What do your suggest I do or should I even do it? I have Spring, Struts, Log4J, Hibernate and JAX-RS in the project.

like image 744
Varun Achar Avatar asked Aug 21 '11 16:08

Varun Achar


People also ask

How do you Mavenize a project?

Simply, just add the pom. xml file under your root (context) project folder. This will make your project as Mavenize project. Once you have added the pom file, then you can execute maven build life cycle commands from IDE terminal.


1 Answers

Ok.. I did eventually shift the project to maven. Here's what I did.

  1. Download the m2e eclipse plugin. It is your best friend!
  2. Create a skeletal maven project. src/main/java is where your code should reside. Move your code into the src/main/java folder. You can continue to use your existing package structure. No need to change that. Even code change isn't required since maven sets src/main/java as the source folder, so you don't need to change the package declarations.
  3. Move your unit tests to src/test/java. Again, no need to change package declarations.
  4. DO NOT copy your libraries & jars.
  5. Check all the compilation errors caused because of the missing jars.
  6. Add dependency of each missing jar to pom.xml. You can get the dependency from the maven repository websites. If you have already indexed the repositories in m2e plugin, then you can simply search of the dependency within the plugin and add it from right there.

In case you have a multi module project, then convert the other modules to maven as described above and add the dependent module to pom.xml of the other module.

If you have custom jars which aren't maven based, you can add them in the src/main/resources folder and then add the jars to build path.

There you go! Easy peasy!

I have a skeletal project setup for Spring + Maven + EC2. You can use that for creating, configuring maven and automating deployment process.

https://github.com/varunachar/maven-release

like image 193
Varun Achar Avatar answered Oct 14 '22 21:10

Varun Achar