Import Maven multi-module project into Eclipse
Asked Answered
S

8

27

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?

Shiri answered 2/9, 2017 at 8:30 Comment(1)
Can you share a screenshots to describe presented as deep directory structure && I expand the submodule project, I don't see the java packages shortcutsPowerhouse
D
16
  • 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.

Drawstring answered 2/9, 2017 at 8:46 Comment(3)
It sounds like that is what was already done. As I see it, the submodules aren't selectable. Only the parent POM project is selectable in Eclipse 2018.09.Oleaster
I would agree with @Oleaster - in my case though I can select individually both parent and modules. When all of them are checked, the environment behavior is as described in the question. When only the modules are selected, they are imported and viewed properly (Java Resources is visible, packages are automatically shown grouped) (Red Hat Developer Studio 12.9.0.GA based on Eclipse)Virtuosity
@Drawstring Could you please provide the link of M2E plugin or screenshot? Upon searching in eclipse marketplace, I can see a lot of of plugins (not anyone specific with name as only M2E)Gripsack
P
12

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.

Pronghorn answered 13/2, 2021 at 15:46 Comment(0)
Z
6

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 !

Zacharia answered 13/2, 2020 at 10:3 Comment(0)
T
2

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

Teddman answered 26/1, 2019 at 8:55 Comment(0)
C
2

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.

Chaschase answered 20/8, 2019 at 11:14 Comment(0)
P
0

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!

Polarization answered 26/2, 2019 at 8:58 Comment(1)
can Eclipse open the sub-modules under main root project? Is there a setting for this?Chuvash
P
0

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.

Parris answered 15/2 at 11:48 Comment(0)
R
-1

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.

Ruthven answered 2/9, 2017 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.