简体   繁体   English

“主要” java.lang.NoClassDefFoundError:org / apache / http / HttpEntity

[英]“main” java.lang.NoClassDefFoundError: org/apache/http/HttpEntity

I'm trying to use the apache http library in my project. 我正在尝试在我的项目中使用apache http库。 I imported the libreries in my project http://imgur.com/WvwqcDS 我将库文件导入了我的项目http://imgur.com/WvwqcDS

When I run my program, I get this error: 运行程序时,出现以下错误:

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

The ClassLoader can't find org.apache.http.HttpEntity, which should be inside "httpcore-4.3.jar". ClassLoader找不到org.apache.http.HttpEntity,该文件应位于“ httpcore-4.3.jar”内。 Open the jar as an archive and verify that it contains org/apache/http/HttpEntity.class. 打开罐子作为存档,并验证它是否包含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). 在Eclipse中,转到“运行”>“运行配置...”,然后找到您的主类的Java应用程序配置文件(根据截图,该类应为“ Launcher”项目中包含主方法的类)。 Under the Classpath tab, you should see your library jars listed. 在“类路径”选项卡下,您应该看到列出了您的库jar。

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). 如果不是,请返回到“导航”窗格中的“启动器”项目,右键单击并选择“属性”,转到“构建路径”,删除jar,按OK,然后返回并再次添加它们(以确保日食元数据是新鲜的)。 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. 另外,在“订单和导出”选项卡下,最好检查所有jar,以便如果将Launcher作为另一个项目的依赖项包含在内,则这些jar将被传递。

您的Eclipse在查找外部jar时遇到麻烦,请尝试将其导入到您的工作区中,或者使用“添加外部jar”将它们引用到外部

In my case Maven was not updating dependencies properly. 在我的情况下,Maven没有正确更新依赖关系。 I use mvn clean and then re-updated dependencies then it got fixed. 我使用mvn clean,然后重新更新了依赖项,然后它得到了解决。

暂无
暂无

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

相关问题 java.lang.NoClassDefFoundError:org / apache / http / HttpEntity - java.lang.NoClassDefFoundError: org/apache/http/HttpEntity 线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / http / HttpEntity - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/http/HttpEntity 线程“main”中的异常 java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient - Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient 线程“ main”中的异常java.lang.NoClassDefFoundError:org / apache / http / NoHttpResponseException - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/http/NoHttpResponseException 线程“main”中的异常java.lang.NoClassDefFoundError:org / apache / http / ConnectionReuseStrategy: - Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/http/ConnectionReuseStrategy: java.lang.NoClassDefFoundError:org / apache / http / impl / conn / PoolingClientConnectionManager - java.lang.NoClassDefFoundError: org/apache/http/impl/conn/PoolingClientConnectionManager java.lang.NoClassDefFoundError:带有AmazonHttpClient的org / apache / http / conn / SchemePortResolver - java.lang.NoClassDefFoundError: org/apache/http/conn/SchemePortResolver with AmazonHttpClient java.lang.NoClassDefFoundError:org / apache / http / conn / HttpClientConnectionManager - java.lang.NoClassDefFoundError: org/apache/http/conn/HttpClientConnectionManager java.lang.NoClassDefFoundError:org / apache / http / conn / scheme / SchemeSocketFactory - java.lang.NoClassDefFoundError: org/apache/http/conn/scheme/SchemeSocketFactory java.lang.NoClassDefFoundError: org/apache/http/message/BasicNameValuePair - java.lang.NoClassDefFoundError: org/apache/http/message/BasicNameValuePair
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM