I know there were times it was very hard to us to move Java Projects to Maven. Lots of hurdle moving files from one directory to another, adding dependencies, etc.
You may need to install m2e-eclipse plugin in order to have this simple utility in Eclipse.
In your eclipse just right click on Java Project
and click Configure
and you should see “Convert to Maven Project
” option.
You should see dialogue like this below. Just add “Name
” and you should be all set.
Don’t forget to add your all custom dependencies in pom.xml
file.
Here is a sample pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>CrunchifyJerseyEmbeddedHTTPServer</groupId> <artifactId>CrunchifyJerseyEmbeddedHTTPServer</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <warSourceDirectory>WebContent</warSourceDirectory> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> </build> </project>
The hardest thing in ant to maven conversion is finding the correct dependency versions. Usually what everyone does is look inside jar META-INF folder and find the pom.xml. But there are cases you cannot find the exact version of a jar.
The most accurate method in this situation is to calculate the jar file hash and do a reverse search in Nexus repository. File hashes can be calculated with the help of Microsoft FCIV utility.
Everything is explained in this article step by step.
Thanks Dinusha for detailed comment. Appreciate it 🙂
I’ve slight difference suggestion also for readers. It’s also a good practice to upgrade dependencies to latest version to get all latest security fixes.
Nice and simple article. thanks.
You are welcome Madhukumar. Happy coding.
Thanks
You are welcome Yevhen.
Really a nice article. Thank you so much.
You are welcome Abdullah 🙂
Hi App, Nice Article. How to convert the existing application into Maven project from resource level.?, because I am having 4 projects under a single application.
Thanks for this article.
Hi Srikanth – thanks. So you have 4 different projects in Eclipse environment? I didn’t get you what you mean by 4 projects under single application?
Could you please share some more light?
Didnt work, unfortunately. It just added a pom file, but didnt convert dependencies.
Hi Anton – this should work as it is. Did you get any exception? Which version of Eclipse are you using?
Hi App – thanks for nice article. Worked like a charm for me. Really Appreciate your all work on Crunchify. Would like to join Crunchify. Do we have any open position?
Thanks.
Thanks Rakesh for your nice comment. Regarding career opportunities please visit https://crunchify.com/join-the-team-crunchify-is-looking-for-new-contributors/
Thanks,
App Shah
How can I run this in command prompt?
Hi Dhana – you mean converting project into Maven via command prompt? I don’t know. Need to check.
Excellent. Why didn’t you expand on proofreading the
POM.xml file to validate the entries? As the JSF project may or may not have duplicate entries or incorrect entries, as the POM file would be the controlling tool for a CLEAN project ? yes ? no ?
Hi there – didn’t get your question clearly. Could you help explain in details? Or help provide solution too if you have it.