Introduction to Maven Eclipse Plugin
Maven project can be created without using any specific IDE by using only text editor such as gedit of notepad i.e using the command-line interface(CLI). However, as most of the maven framework and technology are used in java projects it is convenient to use maven in the IDEs for java projects. One of the most preferred IDE for java projects is the Eclipse IDE. Now, even though new maven projects can be created in Eclipse IDE. There is often a necessity to import the existing maven projects in eclipse. For this eclipse plugin was being used create the files for eclipse IDE such as .project, .classpath files, and .settings folder that are required by an eclipse for using maven project. In which mvn eclipse: eclipse command of maven eclipse plugin was being used to generate these files that will be further useful when the same project was opened in eclipse. However, this plugin usage is deprecated now and the use of M2E or maven2E that stands for maven to eclipse integration should be used. It makes the task to use the existing maven project in eclipse IDE easily and effectively and also provides us with other features. In this article, we will learn the assistance of the maven plugin, how to install it in eclipse and use it to import the existing maven project in eclipse IDE.
The Assistance of M2E Maven Eclipse Plugin
This plugin provides many features that can be used for easy and efficiently using the maven projects using java language. Some of them are listed here:
- It provides integration between eclipse IDE and maven projects.
- It helps in viewing the remote and local maven repository’s contents.
- It provides the facility to create new maven projects that can be single-module or multi-module maven projects in eclipse IDE.
- This plugin helps us to import the existing maven projects in the IDE.
- Provision of managing, viewing, and changing the pom.xml file in the graphical format.
- Plugins and dependencies can be managed and searched easily.
- Building the maven project becomes simpler by using the maven builds and this plugin.
Installation -The M2E eclipse plugin is already installed in the eclipse IDE and can be checked by going to the following path to check maven eclipse plugin:
Window -> Preferences -> search for Maven/ view in the list on the left side of the window as shown in the below image:
If this plugin is not pre-installed in your eclipse IDE, you can download and install the latest release of this plugin by navigating to the following path in eclipse –
Help -> Install New Software…
You will see a list of already downloaded packages.
Enter the name of the site from where you want to download the plugin in work with section.
For our purpose, We will enter http://download.eclipse.org/technology/m2e/releases link to get the latest release of m2e plugin. Then click on the add button and add a new repository. Then click ok and complete the installation of m2e plugin in your eclipse.
1. Check Plugin Indexing for the Local Repository
Before we provide for the sections of creating new maven projects and importing existing maven projects, it is necessary to make sure that the local repository is indexed properly. To navigate to the repositories of the maven you can follow the following path –
Windows -> Show View and then click on other options that will open the show view window. Search for repositories and you will see the option of maven repositories as shown in the image –
After choosing the maven repositories option you will be displayed with the following list of repositories –
By opening the local repositories option, you will see the local repository paths. You can rebuild the index of these repositories by right-clicking on them and click on the rebuild index. It is also preferable to rebuild the index of the global repository to maven central repository but it is time-consuming and requires internet connection. Now, let us proceed with creating a new maven project in eclipse IDE.
2. Creating a Maven Project
You can create a new maven project simply by clicking on the File -> New -> others that will pop out the following window where you can search for maven and choose maven project option –
Click on the create a simple project on the next window as shown below and click next.
Then enter the artifact is and group id of the maven project you wish to create and click on finish. In my case, we have entered com.educba as my group id and demo-eclipse-plugin as my artifact id as shown below –
That will lead to the creation of your new maven project with following project structure that can be seen in project explorer window.
3. Importing Existing Maven Project
You can add the existing maven project created by you using CLI i.e command-line interface or any other editor to the Eclipse IDE with the help of the M2E maven eclipse plugin integration. You can delete the .project, .classpath files, and .settings folder that are present in your maven project. For example, we have the following maven project that we have to import in eclipse in which we will delete the above-mentioned files. The above files and folders are hidden. Make sure to make settings to see hidden files and delete them.
Now, click on the file -> Import option in your eclipse IDE and where you will see a popup window of import. Search for maven and choose existing maven project option after which you will see following window –
Choose your root directory that in my case is chosen as shown below and then click on ok. After that click on finish.
After that, you will see that your project is imported in your eclipse Ide and its project structure can be seen in the project explorer window as shown below.
You can go to your project directory and see that all the project-related files that will be used by eclipse Ide that we previously deleted will have been created again after importing the maven project in eclipse because of using M2E plugin.
We can make the use of the M2E eclipse plugin of maven for importing existing maven projects in eclipse IDE or creating the new maven project and managing the build process and dependencies in your maven project.
This is a guide to Maven Eclipse Plugin. Here we discuss the use of the M2E eclipse plugin of maven for importing existing maven projects in eclipse IDE or creating the new maven project. You can also go through our other suggested articles to learn more –