How to Create Java Project with Maven in Eclipse - Step by Step Guide

If you are not using Maven for managing dependency and creating a build for your Java project, then you are definitely missing something. Being an ardent fan of ANT, I started with Maven quite late, but once I started, I haven't looked back. Maven makes it so easy to add new open-source JAR files, building and testing your project that you wouldn't look back. By the way, like all the things starting is difficult. I spent countless hours will creating my first Java project using Maven and Eclipse, but those were days with older Eclipse IDE

Now with Eclipse Juno and indigo, you get inbuilt support of Maven, which means it's a lot easier to start working with the Maven-based Java project in Eclipse IDE.

In this article, we will see step by step guide for setting up Maven for Eclipse, updating Maven proxy settings, Installing the M2Eclipse plugin, and finally creating a Maven-based Java project in Eclipse.

Btw, if you are just starting with Maven, I suggest you first go through comprehensive Maven courses to learn some fundamentals. It will not only help you to build and deploy your Java and Spring Boot projects using Maven but also learn Maven itself in depth.




How to Setup Maven in Eclipse? Example and Guide

Before creating a Java project using Maven in Eclipse, you first must set up your Eclipse with the correct plugin. If you are starting it fresh then you can follow the below steps

1. Download Eclipse IDE, both Eclipse Juno and Indigo versions will work.

2. Install Maven Integration for Eclipse Plugin, you can install this by searching for it on Eclipse Market Place.

How to Create Java Project with Maven in Eclipse - Step by Step Guide


3. Restart Eclipse
When you install the Maven plugin, they come with bundled apache Maven and they create a Maven repository in your User directory like C:\Users\YourUserName\.m2\repository. This means you don't need to manually download and install Apache Maven by yourself.

By the way, if you are running under proxy than, you need to update Maven's settings.xml file, without this Maven will not be able to download dependencies and plugins when required.

To update Maven's Internet connection proxy settings, you can edit the following block of Maven settings.xml. This file can be found inside C:\apache-maven-3.1.0\conf\settings.xml or your specific download folder if you are not using embedded Maven, otherwise in location C:\Users\YourUserName\.m2\settings.xml.

-




        optional
        true
        http
        proxyuser
        proxypass
        proxy.host.net
        80
        local.net|some.host.com



Once you are done with your changes, you can save settings.xml, but remember to click the update settings button on Eclipse, otherwise, your changes will not be picked up by Eclipse and you will spend countless hours on mysterious Maven issues, which hardly direct you here.

2. How to Create a Maven-based Java project in Eclipse?

Now, we are ready to start. It's very easy to create a Maven-based Java project, once you have set up Maven and installed the Maven Integration plugin for Eclipse. Here are the steps to follow

1) Create New Project, and choose Maven -> Maven Project

2) Select simple archetype and default workspace location, you can choose any workspace location or archetype but for this demo, default settings are good enough.

3) Put meta details for a project like groupId, artifactId, project name, etc.

4) Done, your project is created, you can view them in Project Explorer.



That's all folks. You can see how easy it is to create a Maven-based Java project in Eclipse. You can also follow the same steps if you are still using Eclipse Indigo. The key thing is to install the Maven Integration Plugin for Eclipse, also known as M2Eclipse. This makes your life much easier, and once you start working with Maven, you will not going to turn back, because Maven does a fantastic job of managing dependencies, downloading JAR files and libraries.

Enjoy working with Java, Maven, and Eclipse, and let me know if you face any issues while creating a Maven-based Java project in Eclipse IDE.


Other Maven Eclipse articles you may like to explore
  • Difference between Maven, ANT, and Jenkins? (answer)
  • Top 10 Maven Plugins Every Java developer should know (see here)
  • How to install Maven on Windows 10? (tutorial)
  • How to increase the heap size of Maven? (steps)
  • How to remote debug Java applications in Eclipse? (tutorial)
  • 10 Eclipse debugging tips Java developers should know? (see here)
  • Free Maven books for Java developers (see here)
  • How to fix invalid target release errors in Maven build? (solution)
  • Top 5 Courses to learn Apache Maven for Java (courses)
  • 10 Courses to learn Java for Beginners (courses)
  • Maven - 10 Things Java developer should know (maven)

P. S. - If you are new to Maven and looking for some free stuff to start with your Maven journey, then you can also check out this list of free Maven courses for Java Programmers.

No comments:

Post a Comment

Feel free to comment, ask questions if you have any doubt.