Convert existing java project to Maven in eclipse

Hi java Folks,

Today, we will discuss how we can convert an existing Java project to Maven in eclipse.

To use eclipse utility of converting an existing java project to maven there should be maven installed in eclipse. If maven is not installed in eclipse then you need to install maven in eclipse. To do so following are the steps:

By this, maven will be installed in eclipse.

Now, right click on the project which you want to convert to Maven and click “Configure” and then “Convert to maven project“.

maven

It will show following dialog.

maven_1

Group Id, Artifact Id and version can be set as default. Add value for “Name” and “Description“. These options are optional. Click on “Finish“.

It will convert java project to maven and will create following 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>javaproject</groupId>
  <artifactId>javaproject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Here sourceDirectory element describes the source directory of java.

In pom.xml, there is no any dependency by default so we have to add project dependencies manually by adding following element inside the “project” element.

<dependencies>
Add all the dependencies here...
</dependencies>

This is all about how to convert an existing java project to maven.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s