Java NoClassDefFoundError building WAR file

时间:2016-02-12 22:04:19

标签: java eclipse glassfish

I'm attempting to build my a .war file for my web module and exporting it to an autodeploy folder. However, it always crashes on this error:

Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest

I'm using Eclipse Luna as my IDE and all the apache jars are added to my build path. Is there somewhere else I have to add them for this to work?

enter image description here

2 个答案:

答案 0 :(得分:0)

检查POM文件中是否有HttpClient依赖项。 如果没有,你需要添加:

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.1</version>
</dependency>

如果您不使用maven,请下载jar并添加类路径。

答案 1 :(得分:0)

您应该将apache jar放到web project's > Webcontent > WEB-INF > lib文件夹中。

您的代码似乎已成功编译,因为它们位于您项目的类路径中。但是在运行时,您的Web项目的类路径没有意义(它适用于编译时)。在运行时,那些apache jar应该在运行时类路径上的某个地方(某处像WEB-INF / lib文件夹或EAR / lib文件夹或应用程序服务器的运行时类路径等...)