开发Web应用程序时应该将外部JAR文件放在哪里? [英] Where should I put external JAR files when developing a web app?
问题描述
StringUtils
),我很困惑我应该把jar放在哪里( / lib
, / WEB-INF / lib
?),如何配置我的类路径(在Eclipse中)。 我尝试将JAR放在上述两个地方,并通过点击将JAR加载到类路径添加JAR
在项目属性中,两个解决方案编译都很好,但是给出如下运行时错误:
SEVERE:Servlet.service()抛出异常
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)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206 )
在org.apache.catalina.core.StandardWrapperValve.invoke(Stand ardWrapperValve.java:233)
在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java: 127)
在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
在org .apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:588)
在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489)
在java.lang.Thread.run(未知来源)
所以...如何加载外部JAR?
请注意,我不太熟悉外部JAR的加载方式在Java中,虚拟机,或者Eclipse如何管理它,所以我可以欣赏详细的解决方案。
yourapp / WEB-INF / lib中
。 (在eclipse你正在正确添加它们)。所以确保罐子真的在那里。请注意,如果您从eclipse启动应用程序,则必须配置部署组装。
部署程序集通过右键单击> ;属性> eclipse中的部署程序集
。在那里你应该添加你的Java构建路径条目
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 clicking 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"
这篇关于开发Web应用程序时应该将外部JAR文件放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!