Eclipse Build Path Nesting Errors

128,932

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...:

  1. Go to the navigator and press right click on the project
  2. Build Path
  3. Configure Build Path
  4. Source (tab)

Exclusion Patterns

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:

  1. Right click the project >> properties >> build path;
  2. In Source tab, Select all the source folders;
  3. Remove them;
  4. 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":

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.

Share:
128,932
AvatarHill
Author by

AvatarHill

Updated on July 10, 2020

Comments

  • AvatarHill
    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'
    

    enter image description here

    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
    smwikipedia over 8 years
    This is just one of the many random tricks. Not explaining why. Thus less helpful.
  • Beezer
    Beezer almost 8 years
    I just renamed the pom entry to scr/main/java and all was good. Thanks for the post acheron55
  • Line
    Line over 5 years
    did you put it there? or where does it come from?
  • user1807337
    user1807337 over 3 years
    Thank you for saving my day!
  • Matheus Santz
    Matheus Santz about 3 years
    You deserve the World my dear! Thank you so much. That was all about incorrect Maven structure.
  • Balu
    Balu about 3 years
    This <sourceDirectory>src</sourceDirectory> appeared in my pom.xml after I changed the JDK version of the maven-compiler-plugin.
  • The Dark Knight
    The Dark Knight over 2 years
    Great answer . Exactly the problem that I was facing . Upvoted .
  • Michael Skarn
    Michael Skarn almost 2 years
    This worked perfectly for me without having to alter any configurations.