Hi friends, in this tutorial, I will show you how to Convert an existing Java project to a Maven project in Eclipse. It is very easy and simple to convert a Java project but in order to do that you may need to install the m2e-eclipse plugin in Eclipse IDE. If you want to start or create a new Maven project, please read the following tutorial — how to create a Maven project in Eclipse IDE. Ok, let’s start to convert an existing Java project to a Maven project. Please follow the below steps —
Convert an existing Java project to a Maven project
let’s assume, already you have an existing Java project in your Eclipse IDE. Now Right-Click on your project and choose Configure->Convert to Maven Project
Next, you will get another window where you have to provide the Group Id and Artifact Id. Group Id is a unique identifier which identifies you project among all others, so we need to force a naming schema and it should follow the Java’s package name rule. This means it must start with a reversed domain name you control. For example, com.mtb.mtbJavaProject. Artifact Id is the name of jar file without any version. The Name and the Description, you can leave these blank also. At last click on Finish button.
Now, if you look carefully in the project you will see a new file pom.xml (Project Object Model) in the root location. The pom.xml file contains the project configuration details used by Maven and it provides all the configuration required for a Maven project.
pom.xml – After converting to a Maven project
<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>com.mtb.java_project</groupId> <artifactId>MtbJavaProject</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>MtbJavaProject</name> <description>This a tutorial on how to convert an existing Java project to a Maven project</description> <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> </plugins> </build> </project>
That’s all friends. You can see and realize that it is really very easy and simple to convert an existing Java project to a Maven project in Eclipse IDE.
If you face any problem feel free to inform me in the comment section below. Please like and share this tutorial on “Convert an existing Java project to a Maven project” with others. Kindly subscribe Mitrajit’s Tech Blog to keep yourself updated with the upcoming article.