我正在使用 Struts2 框架并使用 HttpClient 类来发出 put 请求。 当我尝试在 LoginAction 类中调用 httpClient 的 requestEntity 方法时,出现以下错误。
严重:启动过滤器 struts2 时出现异常 java.lang.NoClassDefFoundError:org/apache/commons/httpclient/methods/RequestEntity
我已将所有必需的 jar 文件包含在类路径中。
请帮我找出问题所在。
最佳答案
如果您使用的是旧版本(apache commons 小于 3.0),那么该类在旧 jar 中将不可用。您必须使用 Apache commons 3.0 库。 org/apache/commons/httpclient/methods/RequestEntity
类是从 v3.0
开始添加的。检查javadoc .
通常,如果我们没有在类路径中(或不在项目中)添加jar,那么我们会得到ClassNotFoundException
,如果我们在项目中包含jar并且它在类路径中,但特定的类不可用,那么我们得到NoClassDefFoundError
。
关于java - Struts2 框架中的 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11957465/