简体   繁体   English

在开发Web应用程序时,我应该在哪里放置外部JAR文件?

[英]Where should I put external JAR files when developing a web app?

I'm developing a dynamic web application with Java (Servlets/JSP) in Eclipse. 我正在Eclipse中使用Java(Servlets / JSP)开发动态Web应用程序。 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). 我正在尝试使用外部JAR(我正在使用来自Apache Commons的StringUtils )并且我很困惑我应该把jar放在哪里( /lib/WEB-INF/lib ?)以及我如何需要配置我的类路径(在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: 我尝试将JAR放在上述两个位置,并通过单击项目属性中的Add JAR将它们加载到类路径中,并且两个解决方案都编译正常,但是给出了运行时错误,如下所示:

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 严重:Servlet的Servlet.service()UserList在cs236369.hw5.servlets的cs236369.hw5.db.MySqlDbHandler.insert(MySqlDbHandler.java:58)抛出了异常java.lang.NoClassDefFoundError:org / apache / commons / lang / StringUtils .UserList.doGet(UserList.java:50)位于org.apache的javax.servlet.http.HttpServlet.service(HttpServlet.java:617)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)。 catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.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)atg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)at 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) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler。在java.lang.Thread.run(未知来源)的org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489)上的进程(Http11Protocol.java:588)

So... how do I load external JARs? 那么......我如何加载外部JAR?

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. 请注意,我不熟悉外部JAR如何在Java,VM或Eclipse管理它的方式中加载,因此我将非常感谢详细的解决方案。

They must be placed in yourapp/WEB-INF/lib . 它们必须放在yourapp/WEB-INF/lib (In eclipse you are adding them properly). (在eclipse中你正确地添加它们)。 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. 请注意,如果您从eclipse中启动应用程序,则必须配置部署组装。

The deployment assembly is configured through right click > properties > deployment assembly in eclipse. 通过在eclipse中right click > properties > deployment assembly集来配置right click > properties > deployment assembly There you should "Add" your "Java build path entries" 你应该“添加”你的“Java构建路径条目”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Eclipse动态Web项目:我应该在哪里放置资源文件 - Eclipse dynamic web project : where should I put resource files 在尝试创建 JAR 文件时,您应该将资源(即图像和声音文件)放在哪里? - Where is the right way that should you put your resources (i.e Images and Sound files) when trying to create a JAR file? 如果我将EJB的文件放在EAR文件中,应该将实体类放在一个单独的jar或Web应用程序中吗? - If I put EJB's in an EAR file, should I put the entity classes in there, a seperate jar, or the web app? 我应将外部xslt文件放在Java Web应用程序中的什么位置? - Where should I place external xslt file in java web app? 编译/运行Java文件时应在哪里放置-cp - Where should I put -cp when compiling/running java files 我在哪里把jar文件放在Tomcat 6中? - Where do I put jar files in Tomcat 6? 我应该在哪里存储网络应用程序的文件? - Where should I store files for my web-app? 将i18n文件放在没有WEB-INF文件夹的实用程序jar中的位置 - Where to put i18n files in utility jar which has no WEB-INF folder 我应该在哪里将配置文件放在Web服务中 - where should i put the configuration files in a webservice 我应该将Java应用程序的图像放在哪里? - Where should I put the images for the Java app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM