Create new Maven project - In 2 minutes

You are here : Home / Core Java Tutorials

STEP 1 >
Go to File, New, Other..

STEP 2 >
Type Maven project and select Next >

STEP 3 >
Tick Create a simple project (skip archetype selection)
Enter project Location = (I have used default workspace location)

STEP 4 >
Enter Group Id : com.ankit (this is package name)
Enter Artifact Id :  MyMavenProject (This is project name displayed in eclipse)
Enter Version : 0.0.1-SNAPSHOT
Enter Packaging : jar (available options are jar, war or pom)
Enter Name : MyFirstMavenProject (Actual Project name - This name is not displayed in eclipse)  (Optional)
Enter Description : This is my first Maven Project (Optional)

And click Finish

STEP 5 >
Project structure in Eclipse>
pom.xml is the deployment descriptor file.

pom.xml looks like this >
<project xmlns="" xmlns:xsi=""
   <description>This is MyFirstMavenProject</description>

STEP 5.1 >
Currently it is not a java project (J icon is missing)
We will make it java project  (Observer carefully : You can see J icon - This j indicates that it's a java project)

STEP 5.2 >
Now, Project structure in Eclipse>
You can see that JRE System Library is added now.

If in case you face this error - Source folder is not a Java project - in eclipse. Click here to solve it.

STEP 6 >
Adding dependencies in pom.xml
<project xmlns="" xmlns:xsi=""
   <description>This is MyFirstMavenProject</description>
          <!-- Add dependency -->
          <!-- You can add more dependency -->

STEP 7 >
Now, Right click on pom.xml > select Run As > Then Maven clean  

Now, Right click on pom.xml > select Run As > Then Maven install

Refresh the project (F5 or by doing right click on project) - Required only if dependency are not updated.

Right click on project - Maven - Update Project..  (Alt + F5) - Required only if dependency are still not updated.

STEP 8 >
Now, add New Java Class - MyMainClass
And run it as Java Application

import org.apache.commons.lang.StringUtils;
public class MyMainClass {
   public static void main(String[] args) {
          String str = "abcd";
/* Output

Output is > true
You can see that jar (apache-commons) which contains org.apache.commons.lang.StringUtils was loaded just by defining its dependency in pom.xml and then following step 7.

STEP 9 >
See final directory structure

STEP 10 > Download
Now, it’s time to Download Project :) Click here.

Read : How to Import Maven project in eclipse - And Troubleshooting while importing

Related links >>

Maven error : No compiler is provided in this environment. You are running on a JRE rather than a JDK?

Difference between Maven Module and Maven Project

Must read for you :