Eclipse Build Path Nesting Errors
Solution 1
I had the same problem even when I created a fresh project.
I was creating the Java project within Eclipse, then mavenize it, then going into java build path properties removing src/
and adding src/main/java
and src/test/java
. When I run Maven update it used to give nested path error.
Then I finally realized -because I had not seen that entry before- there is a <sourceDirectory>src</sourceDirectory>
line in pom file written when I mavenize it. It was resolved after removing it.
Solution 2
I wanted to throw in a non-mavenish answer to this thread.
Due to version control and strict directory structure reasons, I was unable to follow Acheron's answer (the best answer) of doing something similar to removing src/
and adding src/main/java
and src/test/java
to the build path.
I had actually been off-and-on battling this nested build path issue for a couple weeks. The answer to the problem is hinted in the error message:
To enable the nesting exclude 'main/' from 'final/src'
Fix
In your build path, you need to edit your Inclusion and Exclusion Patterns
by clicking on Excluded: (None)
and then Edit...
:
- Go to the navigator and press right click on the project
- Build Path
- Configure Build Path
- Source (tab)
There you can add main/webapp/WEB-INF/classes
as an Exclusion Pattern
. Then it should allow you to add main/webapp/WEB-INF/classes
to the build path as a separate source folder.
Solution 3
Here is a simple solution:
- Right click the project >> properties >> build path;
- In Source tab, Select all the source folders;
- Remove them;
- Right click on project, Maven >> Update the project.
Solution 4
Try this:
From the libraries tab:
Eclipse -> right click on project name in sidebar -> configure build path -> Libraries
Remove your web app libraries:
click on "Web App Libraries" -> click "remove"
Add them back in:
click "Add Library" -> click to highlight "Web App Libraries" -> click "next" -> confirm your desired project is the selected option -> click "Finish"
Highlighting "Web App Libraries":
Solution 5
I had the same issue and correct answer above did not work for me. What I did to resolve it was to go to Build Path->Configure Build Path
and under the source tab I removed all the sources (which only had one source) and reconfigured them from there. I ended up removing the project from eclipse and import the maven project again in order to clear up the error.
AvatarHill
Updated on July 10, 2020Comments
-
AvatarHill almost 4 years
I'm working on a simple JSP/Servlet/Tomcat webapp for my class. The professor asked us to use a folder structure that is slightly different than the default dynamic web project structure. Rather than using the webcontent folder he wants all of our source code under src/main/java and src/main/webapp.
When I run the app my welcome file displays fine, but when I try to access my servlets I get:
Http 500 SEVERE: Allocate exception for servlet InitDb
java.lang.ClassNotFoundException. I'm pretty sure it's a build path error. I have final/src on the build path but I am receiving the warning
"Cannot nest 'final/src/main/webapp/WEB-INF/classes' inside 'final/src'. To enable the nesting exclude 'main/' from 'final/src'
I have this in my deployment assembly:
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
When I exclude main/ the warning goes away, but it doesn't fix the problem. I would appreciate any advice. Thanks.
-
smwikipedia over 8 yearsThis is just one of the many random tricks. Not explaining why. Thus less helpful.
-
Beezer almost 8 yearsI just renamed the pom entry to scr/main/java and all was good. Thanks for the post acheron55
-
Line over 5 yearsdid you put it there? or where does it come from?
-
user1807337 over 3 yearsThank you for saving my day!
-
Matheus Santz about 3 yearsYou deserve the World my dear! Thank you so much. That was all about incorrect Maven structure.
-
Balu about 3 yearsThis
<sourceDirectory>src</sourceDirectory>
appeared in my pom.xml after I changed the JDK version of themaven-compiler-plugin
. -
The Dark Knight over 2 yearsGreat answer . Exactly the problem that I was facing . Upvoted .
-
Michael Skarn almost 2 yearsThis worked perfectly for me without having to alter any configurations.