42

I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.

I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.

I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.

Am I missing something?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user646584
  • 3,621
  • 5
  • 25
  • 27

2 Answers2

99

In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.

enter image description here

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 9
    LIFESAVER! That worked, I knew there had to be an easy way, jesus christ, now I can get some sleep, thanks a million! – user646584 Aug 10 '11 at 04:35
  • 1
    Just in case you are using an older eclipse, in version 3.4.2 the name of the option in project properties is 'Java EE Module Dependencies' – Bizmarck Dec 04 '12 at 19:03
  • @bizmark: That's correct. See also http://stackoverflow.com/questions/3511479/business-logic-layerin-servlet-and-jsp/3511933#3511933 – BalusC Dec 04 '12 at 19:05
  • 2
    This information should be in every tutorial on dynamic projects – Boris Jul 05 '13 at 12:49
  • @BalusC-please have a look at my problem http://stackoverflow.com/questions/18249117/how-to-deploy-web-project-on-remote-tomcat-server-outside-eclipse-with-jar-file – Shiv Aug 16 '13 at 03:01
  • This doesn't seem to work so well for native libraries (JNI): it starts fine once, but if you change any code, Tomcat tries to reload the library and you get an error like `java.lang.UnsatisfiedLinkError: Native Library /usr/local/lib/libgdalconstjni.so already loaded in another classloader`. Is there a way to tag it to only be loaded once? Setting the user library to be a system library didn't help. – z0r Apr 02 '14 at 23:15
  • @BalusC thanks alot man. You saved my alot of time. I were searching out for past two days. You answer resolved my question. – Imran Ali Sep 19 '14 at 03:40
4

You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.

Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.

Femi
  • 64,273
  • 8
  • 118
  • 148
  • 1
    I can't find any WAR settings for Dynamic Web projects in Eclipse STS, but I know exactly what you're talking about because that's what I expected after using Eclipse Galileo for years. – user646584 Aug 10 '11 at 04:14