dynamic web project: “java.lang.ClassNotFoundException” despite .jar file in the WEB-INF/lib directory

a 夏天 提交于 2019-12-25 05:32:17

问题


I'm working on an assignment that requires some .jar files. The assignment requires me to do some work on a Tomcat servlet with JSP files.

I included my .jars in the Java Build Path in Eclipse, and copied/added them to the WEB-INF/lib directory.

When I run the project like so: http://localhost:8080/project/ I see the index.jsp page with empty divs where data should be from the code executed via the TestServlet.java.

Looking for the reason why, I see the following error when I check out http://localhost:8080/project/TestServlet:

May 3, 2013 1:22:26 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [TestServlet] in context with path [/project] threw exception [Servlet execution threw an exception]
with root cause java.lang.ClassNotFoundException: com.aetrion.flickr.FlickrException

    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
    at TestServlet.doGet(TestServlet.java:27)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:680)

Which is weird, since, again, I included the .jars in the Java Build Path and copied/added the .jars to the WEB-INF/lib directory.

Any ideas or help?


回答1:


just to be sure, first you put the jar in the web-inf/lib and after you add it in t project > build path > configure build path > add jar , in that order , correct?

try in the "libraries" tab moving the jar at the top or almost the top... would be a problem of visibility




回答2:


You must try to add the jar in your classpath, project > build path > configure build path > add jar (or external jar)




回答3:


Even i had the same problem.This is how I solved it: You can add the external jar to the tomcat folder->lib-> add your external jar in your system ,after adding remove that folder from your project and add again or you can remove the tomcat folder and copy all the jars from tomcat folder->lib and you can add it as your external jars to your project



来源:https://stackoverflow.com/questions/16364820/dynamic-web-project-java-lang-classnotfoundexception-despite-jar-file-in-the

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