ClassNotFoundException when using User Libraries in Eclipse build path

五迷三道 提交于 2019-11-26 01:53:26

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/7005644/classnotfoundexception-when-using-user-libraries-in-eclipse-build-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!