2

我正在尝试在我的项目中使用 apache http 库。我在我的项目http://imgur.com/WvwqcDS中导入了库

当我运行我的程序时,我得到这个错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/HttpEntity
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
        at java.lang.Class.getMethod0(Unknown Source)
        at java.lang.Class.getMethod(Unknown Source)
        at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
        at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.http.HttpEntity
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 6 more
4

3 回答 3

5

The ClassLoader can't find org.apache.http.HttpEntity, which should be inside "httpcore-4.3.jar". Open the jar as an archive and verify that it contains org/apache/http/HttpEntity.class. If it does, the issue is in your launch configuration. In Eclipse, go to Run > Run Configurations... and find the Java Application profile for your main class (which should be the class containing the main method in "Launcher" project, based on the screenshot). Under the Classpath tab, you should see your library jars listed.

If not, go back to your "Launcher" project in the Navigation pane, right-click and select Properties, go to "Build Path", remove your jars, press OK, then go back in and add them again (to guarantee the eclipse meta-data is fresh). Also, under the "Order and Export" tab, it's a good idea to check off all jars so that if you include Launcher as a dependency for another project, the jars are transitively included.

于 2013-10-19T21:52:59.917 回答
1

您的 Eclipse 无法找到外部 jar,尝试将它们导入您的工作区或使用“添加外部 jar”在外部引用它们

于 2013-10-19T18:46:38.547 回答
0

就我而言,Maven 没有正确更新依赖项。我使用 mvn clean 然后重新更新依赖项然后它得到修复。

于 2017-07-11T06:26:29.417 回答