Angelo Fuchs
Angelo Fuchs

Reputation: 9941

Eclipse can't open sub-project of maven-parent-project

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?

Upvotes: 3

Views: 2344

Answers (3)

Timothy Truckle
Timothy Truckle

Reputation: 15624

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.

Upvotes: -2

rob2universe
rob2universe

Reputation: 7628

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).

Upvotes: 2

Angelo Fuchs
Angelo Fuchs

Reputation: 9941

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.

Upvotes: 1

Related Questions