neves
neves

Reputation: 39323

Maven: Eclipse not correctly configuring paths in a project with a parent pom

I have a maven project that I correctly build through the command line (mvn test). It is structured this way:

pom.xml
|-------subdir1/pom.xml
|-------subdir2/pom.xml
|-------subdir3/pom.xml

Inside each of the subprojects dir (subdir[1-3]), I have a structure of:

src/main/java
src/test/java

When I import the project to Eclipse, or update the maven configuration (Alt-F5), the srcdirs are incorrectly added to the BuildPath. I always need to manually remove them and add each one of the java dirs to have Eclipse correctly compiling.

How do configure my project so Eclipse will always correctly add the build paths?

Upvotes: 4

Views: 1358

Answers (4)

rakesh
rakesh

Reputation: 4498

Just to add a point, I used to get similar issues with eclipse while importing maven project, you can run this from cmd prompt mvn eclipse:clean mvn eclipse:eclipse and then refresh or right click->maven->update your project in eclipse.

Also some times eclipse doesn`t import projects properly, you can just remove it from workspace and add again.

Upvotes: 2

shivamgoel
shivamgoel

Reputation: 77

You should check your and see it should not contain src folder.

Upvotes: 0

neves
neves

Reputation: 39323

Ops, silly me. A colleague of mine added to the pom a spurious configuration:

<build>
    <sourceDirectory>src</sourceDirectory>

I just removed it from the configuration to use maven convention and everything worked fine. Thanks for the help.

Upvotes: 5

bhantol
bhantol

Reputation: 9616

Ensure the following in root pom.xml:-

    <modules>
            <module>subdir1</module>
            <module>subdir2</module>
            <module>subdir3</module>
    </modules>

Then in each of the subdirX/pom.xml add parent tag similar to the following. make sure parent coordinates are correct:

    <parent>
            <groupId>your-parent-groupId</groupId>
            <artifactId>your-parent-artifactid</artifactId>
            <version>1.0</version>
    </parent>

Upvotes: 0

Related Questions