05.Getting started with Eclipse IDE & Maven step by step tutorial

In the tutorial “Setting up Eclipse IDE step by step tutorial” we looked at installing Eclipse IDE, importing an existing Java project folder into eclipse, and creating a Java project within Eclipse. Industrial strength Java applications will be using Eclipse with Maven.

Configure Eclipse to work with Maven

We have already have a modified “settings.xml” file in “c:\tools\apache-maven-3.5.0-bin\apache-maven-3.5.0\conf” as per “Setting up Maven step by step tutorial” – “Configure Maven” section.

Step 1: Let’s configure Eclipse to point to this file via “Window –> Preferences“, and in the pop up console select “Maven –> User Settings“.

Configure Eclipse for Maven build tool

Import an existing Maven project into Eclipse

Let’s import the Maven project that we created in “Create a Maven project” at “Setting up Maven step by step tutorial“.

Step 1:File –> Import“, and in the pop up console select “Maven –> Existing Maven Projects“.

Select the previously create Maven project, which has a “pom.xml” file in its base folder.

Check the Maven folder structure & the file contents.

Maven Project Structure

Note: Java projects have a little “J” symbol on top of it whereas a Maven based Java projects have both “M” & “J”.

Step 2: You can run the “HelloWorld.java” by right mouse clicking, and then “Run As–>Java Application.”

Step 3: You can build the “jar” file within Eclipse by selecting the project “simple-maven-project“, and right mouse click to select “Run As–>Maven Install“.

Create a new Maven Project In Eclipse

Step 1: File –> New Project…“, and then in the pop up console select “Maven –> Maven Project“.

Step 2: Select “C\projects” as the location.

Step 3: Select “Quickstart” as the Maven archetype.

Step 4: Assign a Maven “group id” & “artifact id”.

You have a basic Maven project structure to which you can add packages, classes, interfaces, etc. Also, can modify the “pom.xml” file to add more library dependencies & plugins as you see fit. You are now ready to “Create a new Maven Project outside Eclipse & then import into Eclipse

Step 1: From a DOS prompt run:

Step 2: Import “C:\projects\myproject2” as an existing Maven project into Eclipse as shown above.

You are now ready to “Work on the project” within Eclipse.

Upgrade to Java 8 or Later

As you could notice both the Maven projects were Using J2SE 1.5.

Step 1: Select the project “myproject2” within Eclipse and the right mouse click, select “Properties“, which brings up the project properties. Select the “Libraries” tab, and click on “Add Library“.

Step 2: Remove the “J2SE-1.5” library.

Step 3: You must also add the following two lines to the pom.xml file to use Java 8.

The complete “pom.xml” will look like with 4.12 JUnit library:

You can check for the library versions at “http://repo1.maven.apache.org/maven2/” by clicking on the group id “junit”, and then the artifact id “junit”, and finally the version “4.12”. You can see the jar file “junit-4.12.jar“.

Next Java Beginner Tutorial: Setting up GitHub with Eclipse for Maven based Java projects.

(Visited 5 times, 1 visits today)

800+ Java Interview Q&As

Java & Big Data Tutorials

Top