Home > database >  Cannot import nested Maven project into eclipse
Cannot import nested Maven project into eclipse

Time:01-06

I am trying to import a Maven project into eclipse but I am having difficulty getting Eclipse to see the java files as source files and not as resource files.

I am able to clean/build the project via eclipse however.

The project has parent pom.xml which lists several sub projects as modules. If I directly import any of the subprojects it will see the java files as source files, but this will make it difficult to manage different versions of the project if each version will require multiple interrelated projects.

I would ideally like a way to import just the parent project and have all sub projects managed under it.

Project file tree:

ProjectFoo
 .settings
 base
 lib
 SubProjectFooA
|    .settings\
|    scs
|    target
|    .classpath
|    .project
|    pom.xml
 SubProjectFooB
|    .settings\
|    scs
|    target
|    .classpath
|    .project
|    pom.xml
 SubProjectFooC
|    .settings\
|    scs
|    target
|    .classpath
|    .project
|    pom.xml
 SubProjectFooD
|    .settings\
|    scs
|    target
|    .classpath
|    .project
|    pom.xml
 SubProjectFooE
|    .settings\
|    scs
|    target
|    .classpath
|    .project
|    pom.xml
 SubProjectFooF
     .settings\
     scs
     target
     .classpath
     .project
     pom.xml

In the parent pom.xml this is how all the sub projects are added. I am not very familiar with maven and think part of the problem could be the sub projects are added as modules, but I am not certain yet.

<modules>
    <module>SubProjectFooA</module>
    <module>SubProjectFooB</module>
    <module>SubProjectFooC</module>
    <module>SubProjectFooD</module>
    <module>SubProjectFooE</module>
    <module>SubProjectFooF</module>
</modules>

Things I have tried:

  • Pull copy of project from git, run mvn eclipse:clean eclipse:eclipse, then import into Eclipse

  • Directly adding javabuilder and javanature to .project file

CodePudding user response:

Agree: this can be cumbersome, especially with a large number of sub-projects.

The parent pom will typically be its own project. Other projects that use the parent pom will also be their own projects, and linked to the parent pom using Maven.

Files/directories such as .settings, .classpath, .project and pom.xml must be at the top level of an Eclipse project (nesting sub-projects inside another related project will probably not work).

While there may be settings for <modules> in Eclipse & Maven that I am not aware of, everything you have with a src/target folder should be in its own Eclipse project. They can then be setup as dependencies of each other (either in Eclipse, Maven, or both).

CodePudding user response:

In the end I followed khmarbaise instructions. (There was a .project file in the root in the repo that needed to be deleted)

After deleting all .classpath, .project and .settings files, I was able to use the import wizard without any issues.

The only other thing I will add is before I primarily used the package explore in eclipse, this will show each of the sub projects as sperate entities. If you go to the Project explorer it will show the root project in the working set you added it to with the sub projects nested underneath.

  • Related