简体   繁体   中英

Maven multi module project: Modules missing in Eclipse

I've created a new Maven project in Eclipse using an archetype which describes a multi module project. It partially works as excepted and as I'm used to it. In the Project Explorer the modules are shown as projects in the top level instead of subfolders of the parent project. On my hard disk the folder structure shows the modules below the parents root project folder. I'm now used to seeing the same structure in the Navigator but it shows the same folder structure as the Project Explorer.

To make this even more annoying, I created another module manually using Maven => New Maven Module Project . That module behaves as expected. It is shown as a subfolder of the parent in the Navigator and I can commit it.

To visualize it:

Structure on harddisk (and expected in Navigator):

- parentProject
| - module1
| - module2
| - manuallyCreatedModule

Structure in Navigator and Project Explorer:

-parentProject
| - manuallyCreatedModule
- module1
- module2
- manuallyCreatedModule

I already compared the poms and project preferences of the manually created module and the other ones to the last detail and can't seem to find a reason for this different behaviour. The relevant parts of the poms seem to be identical:

parent pom:

<?xml version="1.0" encoding="UTF-8"?>
<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>myId</groupId>
    <artifactId>parentProject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <modules>
        <module>module1</module>
        <module>mdoule2</module>
        <module>manuallyCreatedModule</module>
    </modules>
</project>

Acrhetype modules pom:

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>parentProject</artifactId>
        <groupId>myId</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <artifactId>module1</artifactId>
</project>

Manually created modules pom:

<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>
        <artifactId>parentProject</artifactId>
        <groupId>myId</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../pom.xml</relativePath>
    </parent>
    <artifactId>manuallyCreatedModule</artifactId>
</project>

You'll see that there are no obvious differences. For the modules poms I just omitted the depenencies. The manually created module also uses the maven-ear-plugin and the jboss-as-maven-plugin in the build section, but I can't imagine them to be relevant for the problem.

I also tried creating the module folder from the Navigator, which tells me they already exist. It just doesn't show them.

The reason why I can't work with this behaviour is, if I want to share the parent project to our CVS, Eclipse doesn't offer to commit the modules. I've tried it anyways and have committed the parent project and the one visible module. If I synchronize now, the other modules still don't appear. I could share each module manually into the parent folder in the CVS but I'm affraid of side efffects.

Does anyone know what causes this and how I get a consistent behaviour? I'd be okay with with all of them not showing in the Navigator but then I'd also need a way to commit them. I guess the best solution would be to get all the modules to show themselves in the parent projects folder in the navigator.

UPDATE

Removing the projects from Eclipse (without deleting the files) and re-importing them solved the problem with the inconsistent behaviour. Now I can't see any of the modules below the parent. This leaves me with the problem of how to commit them properly. I could share each module manually into the already committed parent folder but this doesn't seem like the proper approach to me.

UPDATE 2

With the combined help of @Behe and @cowls I managed to come up with this workaround:

  • Removing the projects from Eclipse (without deleting the files)
  • Re-importing only the parent
  • Modules are now shown and I was able to do the initial commit
  • Removing the project again
  • Re-importing the parent and all of the modules

Now the modules are properly committed and can be synchronized. Since this is a workaround (or at least feels like one) I'm still interested in an answer to the following question:

How to get the modules to show themselves in their parants directory so I can commit them without losing the advantage of having the modules as seperate projects in the Project Explorer?

I had the same issue. I am using Version: 4.4.2.RELEASE of Spring Tool Suite. To fix this issue, I right clicked on the parent project and went to Configure --> Configure and Detect Nested Projects. That generated my sub-modules. Prior to this, I had added all my sub-modules to the same Working Set as my parent. You could do that by either right clicking on each sub-module or clicking on the Downward arrow "V" in Package Explorer.

Im not sure why this is a problem.

But this is simply defined by how you import the projects in Eclipse.

If you import just the parent project in eclipse, youll see them in one project in the project explorer.

If you choose to import all the maven projects, they will be seen as individual projects. Either way if you commit them from Eclipse they get committed to the same place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM