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

I am using Maven 3.3.3 along with Eclipse Mars and m2e. Yesterday I created a new Java project and converted it to Maven.

Subsequently, the class path contained only src instead of the standard src/main/java . I was surprised, but I just created the missing folders and ran the m2e "Update Project". This did not solve the problem; m2e still insisted on using only src .

So, I edited the class path manually, as a result I got the usual

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

When I try m2e "Update project", 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 following command line and ran mvn eclipse:eclipse to get this classpath:

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

Now I am completely at a dead end. Why is this happening?

+6
source share
2 answers

Open POM in the POM editor and click on the "Effective POM" tab. Find sourceDirectory . You will probably see something like this:

 <sourceDirectory>src</sourceDirectory> 

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

To fix the problem:

  • Remove the sourceDirectory element from the POM (Note: it may be in the parent POM).
  • Go to the project
  • Select all source folders
  • Remove them from the build path (context menu β†’ Build path β†’ Remove from build path).
  • Refresh Project

The error should now disappear, and the class path will be correct.

+21
source

There are two types of folders that you can create: 1) Package 2) Source folder

1) The package looks like this: enter image description here

To create a package, right-click the desired folder (in my example, I right-click on Java resources) -> Create -> Package

enter image description here

A popup will appear that looks like this:

enter image description here

"Source folder:" Here you select your project. If you don’t see anything there, click "Browse ..." and find your project. If I click "Browse ...", it will show the following:

"Name:" is the name you will give your package.

enter image description here

Note. Packages should be in source folders. The source folders are the parent folder.

2) The source folders look like this: enter image description here

To create the source folder, right-click the desired folder (in my example, I right-click on Java resources) β†’ Create β†’ Source folder

enter image description here

In the "Project Name:" section, enter a name for the project. If you need help, click "Browse ..."

In the "Folder Name:" section, enter the desired folder name.

Error: if you try to create the folder "src / main / resources" and you run this error "Unable to insert" the project name inside the "ProjectName". To enable nesting exception 'main / from

enter image description here

Decision:

- pic 8 -

+1
source

All Articles