This Tutorial Explains How to Integrate Eclipse with Maven, How to Create New Maven Projects and Enhance the Existing Projects to have Maven Capabilities:
Debugging Your Code in Eclipse was explained in detail in our previous tutorial. Eclipse is a very strong IDE for Java and other languages.
Along with many inbuilt features of Eclipse which make it a powerful tool, Eclipse IDE has provided support for the integration of many external tools that are used in development. Tools for build management or configuration management can be easily integrated with Eclipse. Apart from that Eclipse can support many plugins as well.
Read through our Entire Eclipse Training Series for a complete knowledge of the concept.
This tutorial will explore all about the configuration of Eclipse Java IDE with Maven.
What You Will Learn:
What Is Maven?
Maven is a build management tool that is used extensively with Java. Maven eases the process of builds for your application and provides features to automate this process. It is also very helpful when you are aiming for continuous integration.
Along with that, one of the most important features is managing dependencies of the project becomes very easy through Maven. Maven indeed provides multiple features that are worth exploring.
Let us see how to integrate this tool directly through Eclipse.
#1) From the top menu of Eclipse select Help -> Install new Software, and the following window will open.
#2) Click on the Add button highlighted in the above image. An add repository dialogue box will open, enter the following in the two text fields of this box.
Name: Maven
Location: http://download.Eclipse.org/technology/m2e/releases/
Click on the Add button.
#3) The previous install window will start fetching Maven information from the location specified by you, and the window will look as shown below.
This process may take some time until all the elements linked with Maven are fetched. Till then you will see pending in the list of software to install.
#4) Once Eclipse gets all the information, Maven will be displayed in the window as shown below.
Click on the checkbox next to Maven Integration for Eclipse and click on next.
#5) The configuration will start and again a processing bar will be displayed to you. This may also take some time and you need to let Eclipse complete the processing.
Once processing is complete, the next button will be highlighted, click on the same. The information on the items being displayed will be shown as in the below image.
Again click on the Next button on this window.
#6) The license agreement page will be displayed on the next page.
Click on the radio button to accept the terms and click on finish. Once you click on finish the window disappears and you will be able to see a progress bar at the bottom of the Eclipse IDE as shown below:
Once Maven is fully installed, Eclipse will ask you to restart.
Click on Restart Now to complete the configuration.
With this, you have successfully installed and integrated Maven with Eclipse. When Eclipse is relaunched you will be able to work with the Maven projects.
How Eclipse and Maven Work Together?
#1) How to Create a New Maven Project
Go to File-> New -> Project, and you will see the following window.
While going further in this project creation, you will have to select a Maven template type, provide a group ID and an Artifact ID. By creating a project like this you will automatically get a Java project with a correct project structure and a POM.xml.
#2) Converting an Existing Project to a Maven Project
If you have an existing Java project, and after learning about Maven if you want to convert it to a Maven project, then simply right click on the project in the project explorer and select Configure -> Convert to Maven project.
It will show you a default group id and an artifact id by the name of your project. You can keep the same or choose new names and click on finish. Once you click finish, a POM.xml will be created for your project.
The POM.xml will have only basic information and you can add more dependencies as per your requirement. As shown above, the project name has the symbol of Maven on it to show that the project is converted.
Summary
In this tutorial, we have learned about integrating Eclipse with Maven by downloading Maven. We also learned how to create a new Maven project or enhance the existing projects to have Maven capabilities.