简体   繁体   English

Apache HttpClient抛出NoClassDefFoundError

[英]Apache HttpClient throws a NoClassDefFoundError

I have: ubuntu-9.10-desktop-amd64 + NetBeans6.7.1 我有:ubuntu-9.10-desktop-amd64 + NetBeans6.7.1

  1. I just downloaded "Commons HttpClient 3.1 (legacy)" from http://hc.apache.org/downloads.cgi . 我刚从http://hc.apache.org/downloads.cgi下载了“Commons HttpClient 3.1(legacy)”。
  2. I created new application with IDE NetBeans. 我使用IDE NetBeans创建了新的应用程序。
  3. I focused on Projects -> Libraries -> Add JAR/Folder and here added commons-httpclient-3.1.jar 我专注于项目 - >库 - >添加JAR /文件夹,这里添加了commons-httpclient-3.1.jar
  4. By now, I can write "import org.apache.commons.httpclient.*;" 到现在为止,我可以写“import org.apache.commons.httpclient。*;” This is OK. 还行吧。
  5. But, if I try to add any statement included something like this: 但是,如果我尝试添加包含以下内容的任何语句:

     public static void main(String[] args) { HttpClient client = new HttpClient(); } 
  6. It is compiled well. 编译得很好。

  7. But when I run this project, I receive the following errors: 但是当我运行这个项目时,我收到以下错误:

     ***Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.commons.httpclient.HttpClient.<clinit>(HttpClient.java:66) at SimplestAppl.Main.main(Main.java:22) Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:319) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:264) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:332) ... 2 more Java Result: 1*** 

What is wrong? 怎么了?

I tried to download "HttpClient 4.0 (GA)". 我试着下载“HttpClient 4.0(GA)”。 But the result was same. 但结果是一样的。

What you are experiencing is just a missing dependency. 你所经历的只是一个缺失的依赖。 Java developers are used to gather their dependencies themselves, esp. Java开发人员习惯于自己收集依赖项,尤其是。 when it comes to logging frameworks. 当涉及到日志框架时。 Download commons-logging and add it to your classpath. 下载commons-logging并将其添加到类路径中。 Do as well with all other dependencies required by httpclient. 与httpclient所需的所有其他依赖项一样。

You need the dependencies. 您需要依赖项。 If you used maven, they would fetch themselves. 如果你使用了maven,他们会自己取而代之。 Since you aren't, you've got to go download commons-logging (and perhaps others) and toss them in. 既然你不是,你必须下载commons-logging(也许还有其他人)并将它们扔进去。

I'd like to update anyone coming here to the fact that all answers, and especially RocketSurgeon's, helped me solve my issue in the same sense. 我想更新任何来到这里的人,所有答案,特别是RocketSurgeon,都帮助我解决了我的问题。 I had to download commons httpclient (legacy 3.1), logging and codec before my issues were resolved. 在我的问题得到解决之前,我不得不下载公共httpclient(遗留3.1),日志记录和编解码器。

Also of note; 另外值得注意的; using Eclipse I had to extract the .jar-files and import them into Buildpath using "add library". 使用Eclipse我必须提取.jar文件并使用“add library”将它们导入Buildpath。 Did not work with only adding .zip-file. 仅仅添加.zip文件无效。

If you dont want to use Maven, then 如果你不想使用Maven,那么

- build and launch, look at missing dependencies
- identify vendor, fetch the jar to resolve dependencies
- rinse/repeat until you have all dependencies satisfied
- done

anyway you will be never sure if all dependencies are 100% supplied. 无论如何,你永远不会确定是否所有依赖都是100%提供的。 Its usually around 150% or 99%, but never in between 它通常在150%或99%左右,但从不介于两者之间

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM