Advertise with us

Our eBooks

Eclipse and Maven tutorial

In this tutorial we will show how you can create a Maven project from Eclupse using M2Eclipse plugin.

Maven and Eclipse tutorial

The first requirement for this example is that Eclipse is equipped with Maven M2Eclipse. If your Eclipse installation does not have M2Eclipse pre-installed, you can manually install the plugin from the Eclipse Marketplace.

eclipse maven tutorial eclipse maven tutorial

The next step is verifying your Maven configuration. If you have already installed Maven on your Pc (like me) you would like to use the settings from your installation. Otherwise you can use the default (internal) installation of Maven.

eclipse maven tutorial eclipse maven tutorial

You can find the configuration settings in Window | Preferences | Maven| Installations.  Now it's time to create a new Maven Project, using the Eclipse plugin wizard.

eclipse maven tutorial eclipse maven tutorial

In the next screen confirm that you will use a Maven archetype and set up the project properties. Next choose an archetype as starting point for your projects such as the maven-archetype-quickstart:

eclipse maven tutorial eclipse maven tutorial

Next, we will specify the Archetype parameters, such as GroupId, ArtifactId, Version and package, as shown by the following picture:

maven jboss tutorial

We just created a project that is an Eclipse and Maven project. If you inspect the filesystem,you will find that a valid pom.xml file exists in the project root, which makes it a valid Maven project.

The pom.xml file barely contains a dependency to the JUnit framework, which will be used to unit test your application:

<project xmlns="" xmlns:xsi=""





In addition, you will also find .classpathand .projectfiles and the .settings folder which are Eclipse-specific resources, making it a valid Eclipse project as well.

eclipse maven tutorial eclipse maven tutorial
Now test your program. the shortest way is right-clicking on the pom.xml file which shows the available Maven goals (choose Test which will run the test class).

eclipse maven tutorial eclipse maven tutorial

On the other hand, if you want  to customize the Maven execution, create a new Runtime configuration for Maven. In this case, we decided to execute a Main class, using the mvn compile exec:java -Dexec.mainClass=com.mastertheboss.SampleMaven.App class

eclipse maven tutorial eclipse maven tutorial

© 2021 All Rights Reserved.

Please publish modules in offcanvas position.