How to convert java project to maven project in eclipse

Posted on December 3, 2016


In this post, we will learn how to convert a java project to maven project in eclipse.

Technologies used -

  • Eclipse Mars.2 (4.5.2)
  • Maven 3.3.9
  • Java 8

Follow the following steps for converting java project to maven project.

 

Step #1

Create a Java project.

Go to File → Other → Java → Java Project. Click on Next.

maven1.png

Step #2

In New Java Project dialog, provide the project name as MyJavaProject and click on Finish.

maven2.png

You will see the below folder structure of newly created java project.

maven3.png

 

Step #3

Right click on MyJavaProject.

Go to Configure → Convert to Maven Project.

maven4.png

You will see the below dialog. Now add Name and Description and click on Finish.

maven5.png

Step #4

Review the new folder structure of maven project.

maven6.png

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>MyJavaProject</groupId>
  <artifactId>MyJavaProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>MyJavaProject</name>
  <description>This a sample java 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>