Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven suddenly wants src/ instead of src/main/java

Tags:

eclipse

maven

m2e

I'm using Maven 3.3.3 together with Eclipse Mars and m2e. Yesterday, I created a new Java project and converted it into a Maven one.

Afterwards, the classpath contained only src instead of the standard src/main/java. I was surprised but I simply created the missing folders and ran m2e's "Update Project". This didn't solve the problem; m2e still insisted on using only src.

So I edited the classpath manually to end up with with the usual

src/test/java
src/test/resources
src/main/java
src/main/resources

When I try m2e's "Update Project" now, I get this error:

Cannot nest 'foo/src/test/java' inside 'foo/src'. To enable the nesting, exclude 'test/' from 'foo/src'

sigh I went to the command line next and ran mvn eclipse:eclipse to get this classpath:

src/test/java
src/test/resources
src
src/main/resources

Now, I'm completely stumped. Why is that happening?

like image 596
Aaron Digulla Avatar asked Dec 01 '15 08:12

Aaron Digulla


1 Answers

Open your POM in the POM editor and click on the "Effective POM" tab. Search for sourceDirectory. You'll probably see something like this:

<sourceDirectory>src</sourceDirectory>

When you first converted the Java project to Maven, m2e tried to keep the classpath the same. Eclipse Java projects have a different layout by default. They use src/ instead of src/main/java/. There is no test folder since Eclipse projects usually put their tests into a different project.

To fix the issue:

  1. Delete the sourceDirectory element from the POM (Note: It might be in a parent POM).
  2. Go to the project
  3. Select all the source folders
  4. Remove them from the build path (context menu -> Build Path -> Remove From Build Path).
  5. Update the project

The error should now be gone and the classpath should be correct.

like image 74
Aaron Digulla Avatar answered Oct 18 '22 07:10

Aaron Digulla