I'm developing a dynamic web application with Java (Servlets/JSP) in Eclipse. I'm trying to use an external JAR (I'm using StringUtils
from Apache Commons) and I'm confused as to where I should put the jar (/lib
, /WEB-INF/lib
?) and how do I need to configure my class path (in Eclipse).
I tried putting the JARs in both of the aforementioned places, and loading them to the classpath by c开发者_运维问答licking Add JAR
in the project properties and both solution compile fine, but give a runtime error like so:
SEVERE: Servlet.service() for servlet UserList threw exception java.lang.NoClassDefFoundError: org/apache/commons/lang/StringUtils at cs236369.hw5.db.MySqlDbHandler.insert(MySqlDbHandler.java:58) at cs236369.hw5.servlets.UserList.doGet(UserList.java:50) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run(Unknown Source)
So... how do I load external JARs?
Please take note that I am not that familiar with how external JARs are loaded in Java, the VM, or how Eclipse manages it all, so I would appreciate detailed solutions.
They must be placed in yourapp/WEB-INF/lib
. (In eclipse you are adding them properly). So make sure the jar is really there. Note that if you are starting the app from within eclipse, you would have to configure deployment assembling.
The deployment assembly is configured through right click > properties > deployment assembly
in eclipse. There you should "Add" your "Java build path entries"
精彩评论