Where should I host external JAR files when developing a web application?

I am developing a dynamic web application with Java (Servlets / JSP) in Eclipse. I am trying to use an external JAR (I am using StringUtils from Apache Commons) and I am 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 above locations and loading them into the classpath by clicking Add JAR in the project properties, and both compilation options compile, but give the same error:

SEVERE: Servlet.service () for the UserList servlet threw an exception java.lang.NoClassDefFoundError: org / apache / commons / lang / StringUtils at cs236369.hw5.db.MySqlDbHandler.insert5 cs23l s wwt atl .UserList.doGet (UserList.java:50) in javax.servlet.http.HttpServlet.service (HttpServlet.java:617) in 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.vveveva 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.Error .invoke (ErrorReportValve.java:102) on org.apa che.catalina.core.StandardEngineValve.invoke (StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process Hpp. java: 859) at org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process (Http11Protocol.javaβˆ—88) at org.apache.tomcat.util.net.JIoEndpoint $ Worker.run (JIoEndpoint.java-00-0089) in j .lang.Thread.run (Unknown source)

So ... how do I load external JARs?

Please note that I do not know how external JARs are loaded in Java, VM, or how Eclipse manages all this, so I would appreciate detailed solutions.

+8
java eclipse jar web-applications
source share
1 answer

They should be placed in yourapp/WEB-INF/lib . (In eclipse you add them correctly). So make sure the jar is really there. Please note: if you run the application from eclipse, you will need to configure the deployment build.

The deployment node is configured through right click > properties > deployment assembly in eclipse. There you should "Add" your "Java build path entries"

+21
source share

All Articles