Tuomas Toivonen
Tuomas Toivonen

Reputation: 23522

Import Maven multi-module project into Eclipse

How do I properly import a Maven multi-module project into Eclipse? When I import a new Maven project and select the parent pom, I can see the submodules under the parent pom which are visible in the package explorer and project explorer. However, they are presented as a deep directory structure, as if Eclipse doesn't know they are Java projects.

When I expand the submodule project, I don't see the Java package shortcuts as I would have if I opened a single Maven project. I only see it as a deep directory structure. How do I import a multimodule Maven project and open the submodule project to take advantage of Eclipse Java project features?

Upvotes: 27

Views: 32019

Answers (8)

Sorin Adrian Carbunaru
Sorin Adrian Carbunaru

Reputation: 618

In my case the name of the main project after I cloned it was the same as the name that would have been used for one of the modules. Therefore, after cloning the project, I added a suffix to it to change it. After that the import worked just fine.

Another way of solving, at least in my case, would have been to use a name template when importing the project, one that would make the name of the module different than the main project:

enter image description here

This video helped me get back on the track and find what my problem was: https://youtu.be/aF0xP9SXcrE?si=3LDzzb9gbaQwtoaj.

Upvotes: 0

Black.Jack
Black.Jack

Reputation: 1957

  • Install M2E Plugin from Market if it is not already installed
  • From Eclipse IDE choose "File" and "Import" from toolbar. That should lead you to a pop up.
  • Type "Existing Maven Project", or navigate to this under Maven settings.
  • Then select the main pom project from the import menu, and be sure to select entire tree of projects under it.

Before approaching this clean the IDE from the currently wrong imported project, deleting its Maven root pom project and every submodule, but leave them on the disk obviously. I don't recommend the "Convert" options as sometimes that doesn't lead to clean results, especially with big and messy projects.

Upvotes: 16

Guru
Guru

Reputation: 2857

To add a few on top of @BlackJacks answer, ensure that the parent pom in the root of the directory that contains sub-projects contains a modules section:

<modules>
    <module>module1</module>
    <module>module2</module>
    <module>module3</module>
</modules>

So, after the import, unlike IntelliJ, Eclipse opens the sub-modules as separate projects, apart from the main root project.

Hope this helps!

Upvotes: 0

Ahmad Hoghooghi
Ahmad Hoghooghi

Reputation: 155

Step 1

  • Navigate to project folder.
  • Open command prompt (or shell)
  • Run mvn eclipse:eclipse

Step 2

  • Open eclipse IDE
  • Open project from File > Open Projects From File System...
  • Select folder of project containing parent pom.xml file

Step 3

  • Run Project > Clean from Menu

Step 4

  • Run File> Restrat From Menu

Solved my problem in Eclipse 2019-06(4.12.0) and 2018-12(4.10.0)

Important trick

When you start to search for files in 'open resource' (for example using Ctrl + Shift + R) eclipse will show file from two address. for example MySampleFile will be available under:

  • parent-module/sub-module/src/main/java/.../MySampleFile and
  • sub-module/src/main/java/.../MySampleFile

Use second one. Opening file with first one will not activate IDE features on that file.

Upvotes: 3

Fernando Maia
Fernando Maia

Reputation: 199

First, import the parent project. Then, right click on it at the package/project explorer, go to Configure and then click the Configure and Detected Nested Projects..., on the window that will appear click Finish and you're gold.

Also worth mentioning, Package Explorer won't show it nested, use Project Explorer instead.

Have a nice day.

Upvotes: 12

Rayen Rejeb
Rayen Rejeb

Reputation: 341

For everyone who still have the same issue, follow these steps:

  1. Open Import Existing Maven Project wizard
  2. Select the Parent POM.xml only and click Finish
  3. Foreach child project, Right Click on the project folder, then click on Import and select his POM.xml file

Hope it helps ! Good Luck !

Upvotes: 6

Anshu Kumar
Anshu Kumar

Reputation: 633

If you are using git or any version control. Clone the repository first in local.

Steps already explain by @Black Jack. Adding image to support

enter image description here

Upvotes: 2

CHiRAG
CHiRAG

Reputation: 232

Follow the steps

  1. Choose file menu
  2. Click on import
  3. Select project right click then Convert --> Convert to maven project
  4. Click on import then type or select Existing Maven Project

Now your moduled project in you workbench. If you have any query we can discuss.

Upvotes: -1

Related Questions