37

I keep getting the following error after I put the required files in my build path on Eclipse. I am working on a Spring MVC Hello World Application and using Eclipse Helios for Java EE developers:

Jan 16, 2012 1:25:42 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /SpringMVCTutorial threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:415)
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:397)
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:118)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1062)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4957)
    at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5284)
    at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5279)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

I have tried right-clicking the server and clicking "clean". I right click the application, click "Build Path" the "Configure Build Path" and put the right JAR files in the library; however, it still doesn't acknowledge them as dependencies. What am I missing?

I have tried the advice presented here:

  1. Right-click on your Web project
  2. Click 'Properties'
  3. Select 'Java EE Module Dependencies'
  4. Click the 'Web Libraries' tab
  5. Add external JARs (if the JAR is outside of your project). An entry will be added under Jar/Module, make sure you click on the checkbox (checked).

The problem is that when I select "Click Properties", I do not have the option of clicking Java EE Module dependencies, as it doesn't appear. I downloaded any extra Java EE tools and still can't find it.

Sae1962
  • 1,122
  • 15
  • 31
Mike
  • 1,590
  • 8
  • 27
  • 41

4 Answers4

41

In order to get it to work right, I have to "drop and drag" the files that I want in my classpath/dependencies into my the WEB-INF/lib folder. It works this way.

For some reason, when I try to do it the right way

Build path → Configure build path → External jars

it just doesn't take them.

The trick is that I have to put the files int my Web App Libraries folder and the only way to do that (that I can see) is to "click and drop" into my WEB-INF/lib folder. In this way, it automatically shows up in my Web App Libraries.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Mike
  • 1,590
  • 8
  • 27
  • 41
  • I guess if I were not using maven I would put all the jars in the lib directory and then add them to the classpath from there. – Alex Barnes Jan 22 '12 at 18:55
  • Looks like an Eclipse "feature" - I encountered it in the 4.2 (Juno) release too. – mjn Nov 13 '12 at 12:17
  • 4
    If you build with maven: Ignore It in Eclipse for ever: Windows -> Preferences -> Validation -> deactivate "Classpath Dependencies Validator" (at least :) ) – Harald Brabenetz Mar 26 '14 at 18:06
  • 1
    For the record (in case people get here through searches): If I'm not mistaken, what you were after is now (i.e. at least in Luna SR2+) available, through the "Deployment Assembly" tab/section of project properties. There (just above "Java Build Path" on the left hand side), you can do an "Add", select "Java Build Path Entries" and all your dependent jars, so that they're included in your application server (e.g. Tomcat's) appropriate folders while running/debugging inside IDE. – OzgurH Oct 11 '16 at 16:28
  • I fixed my problems using this answer. The fact that it didn't work by adding them using `Build Path -> .. -> Add External JARs...` is that you need to add them using `Build Path -> .. -> Add JARS...` and then select the ones that are in your **WEB-INF/lib** folder. This did the trick for me. – WannaGetHigh Jun 01 '18 at 08:32
  • Still an Eclipse "feature", encountered in 2019-12 (4.14.0). Just copy pasting into WEB-INF/lib solves the issue – Neoraptor Feb 02 '20 at 06:58
26

When adding new jar files, I got two messages on Eclipse's Problems Tab: one error and one warning. I only solved this problem when combining all previous solutions with an extra step. Here's how I solved it:

  1. "Drag and drop" the files that I want in my classpath/dependencies into my WEB-INF/lib/ folder;
  2. Right-click on your project in the Package Explorer tab, and build path --> configure build path --> external jars, adding the desired files;
  3. Restarted Eclipse;
  4. Select Project --> Clean…. My system is configured to build automatically, so after this step, the error message was gone, but the warning XXXXXXXXXXX.jar will not be exported or published. Runtime ClassNotFoundExceptions may result remained;
  5. Right-click on warning message --> Quick Fix;
  6. Select the option Mark the associated raw classpath entry as a publish/export dependency. (in the following figure)

Quick fix for warning message

Erick
  • 391
  • 3
  • 6
2

Right-click on your project in the 'Project Explorer' tab and go to 'Build path' → 'Configure build path' → 'External jars`, and add all the JARs that you want.

Sae1962
  • 1,122
  • 15
  • 31
Ramesh Kotha
  • 8,266
  • 17
  • 66
  • 90
  • The problem is that is what I have been doing but I still get the above referenced errors. The jars that I add remove my compliation errors, but now my dependency errors. Go figure! – Mike Jan 17 '12 at 00:33
0

With Eclipse 2022-03, you can right click on the warning (in Problems view), select quick fix, which give you the option to publish/export the dependent project to /WEB-INF/lib. But it beats me that from the project Build Path we can't do this step manually.

Java Build Path/Projects tab

Yee
  • 861
  • 1
  • 8
  • 13