How to Convert Java Project to Maven Project in Eclipse


In a previous couple of articles, we have seen how to create simple Maven project in Eclipse and how to create maven web project in Eclipse. Now in this article, we will show you how to create a java project and convert it into the maven project.

Tools and technologies used

  • IDE - Eclipse Neon
  • JDK - 1.8
  • Maven - 3.5.3
Let's first create plain Java Project in Eclipse IDE.

Step-1

Create a Java project

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

Step -2

In New Java Project dialog, provide the project name as "JavaDemoProject" and click on Finish as shown in the diagram:
So now we have created plain Java Project, next step is to convert to maven project.

Convert this Java Project to Maven Project

Step-3

Right, click on JavaDemoProject.

Go to Configure → Convert to Maven Project.
You will see the below dialog. Now you can add Name and Description and click on Finish.

Step-4

Review the new folder structure of maven project and also pom.xml file:


Pom.xml

<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>JavaDemoProject</groupId>
    <artifactId>JavaDemoProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <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. Now you can add dependencies you pom.xml and start developing your project.

Comments