2

I have the following project structure:

pom.xml (packaging: pom)
\-- SubProject
  - pom.xml (packaging: jar)
\-- SubProject
  - pom.xml (packaging: ear)

I want to open all three projects in Eclipse.

When I select 'import existing project' it only displays the parent pom.xml (packaging: pom) but not the SubProjects.

(The projects have src, test, etc. and open just fine in Netbeans.)

When I move the parent pom to a subfolder and reference it by <relativePath>, eclipse can open it, but maven warns. So I'd rather not use this.

How can I open the proper Maven project structure in Eclipse?

Angelo Fuchs
  • 9,825
  • 1
  • 35
  • 72

3 Answers3

1

The Eclipse "Import - Maven - Existing Maven Projects" on the parent folder should create two project folder in the eclipse workspace (on the same level).

It works with poms similar to:

Parent

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>parent</groupId>
  <artifactId>test.parent</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <modules>
    <module>mod1</module>
  </modules>
</project>

Module

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>parent</groupId>
    <artifactId>test.parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>mod1</artifactId>
</project>

Nesting the folder in the Eclipse tree is not required (and cleaner).

Angelo Fuchs
  • 9,825
  • 1
  • 35
  • 72
rob2universe
  • 7,059
  • 39
  • 54
1

If you chose "Import existing project into workspace":

After opening the parent project in eclipse, you see the folders with the sub-projects. You can right-click them and select "Import as project" from the context menu.

But you should use the solution of RobE if possible.

Community
  • 1
  • 1
Angelo Fuchs
  • 9,825
  • 1
  • 35
  • 72
-2

you have to name the subprojects explicitly in the main POM modules section.

otherwise you have to navigate into the respective subproject folder when importing the subprojects.

Timothy Truckle
  • 15,071
  • 2
  • 27
  • 51