Angelo Fuchs Angelo Fuchs - 1 month ago 6
Java Question

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?

Answer

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>

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

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

Comments