Convert existing project to a maven project
When I started my project, I wasn't aware of Maven.. I realized the importance of it after th开发者_StackOverflow中文版e 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.
Ok.. I did eventually shift the project to maven. Here's what I did.
- Download the m2e eclipse plugin. It is your best friend!
- 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.
- Move your unit tests to src/test/java. Again, no need to change package declarations.
- DO NOT copy your libraries & jars.
- Check all the compilation errors caused because of the missing jars.
- 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
I faced exactly the same situation like you. Additionally to maven I migrated from JavaEE5 to JavaEE6. I have done the migration step by step:
- Created a maven project
- Created several modules for the maven project depending on the old structure
- Migrated classes from the old project to maven project and added these classes as a jar to the old project
By doing this you have a smooth migration from your existing structure to Maven. At the end of the day you benefit more and more from your maven structures and always are able to further develop your project.
The difficulty will depend on how much you know about maven and how big your project is. It is always easier to play with a small project first and see how it goes. It does not matter what libraries it depends on as long as they are in maven central repository or in a known online location. If the libraries you are suing doesn't exist on any online maven repositories then you will need to deploy you jar files either locally or your own online place. If you cannot find a good hosting service you can even put it on Github. Here is the trick.
There are quite a few interesting articles on converting ant project to maven project which you should read. Here is the first hit on google search http://www.sonatype.com/people/2009/04/how-to-convert-from-ant-to-maven-in-5-minutes/
My only comment is to make the best use of your IDE when you are converting your projects. For example, use refactor features in your IDE when you move your codes. For me, I found that the maven support in Netbeans is extremely useful and easy to use.
In eclipse you can convert exciting project to maven simply by m2e-eclipse plugin.
but in intllje, you can create new maven project and then simply move class to src/java/packagename and configuration to resource folder. then you can add every dependency your project needed from compile error log.
精彩评论