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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19469624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 17:32:57  来源:igfitidea点击:

"main" java.lang.NoClassDefFoundError: org/apache/http/HttpEntity

javaapachehttp

提问by BaluMonster

I'm trying to use the apache http library in my project. I imported the libreries in my project http://imgur.com/WvwqcDS

我正在尝试在我的项目中使用 apache http 库。我在我的项目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.run(Unknown Source)
        at java.net.URLClassLoader.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

回答by MiketheMic

your Eclipse is having trouble locating the external jars, try importing them into your workspace or referencing them outside by using "add external jar's"

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

回答by Bryan W. Wagner

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.

ClassLoader 找不到 org.apache.http.HttpEntity,它应该在“httpcore-4.3.jar”里面。将 jar 作为存档打开并验证它是否包含 org/apache/http/HttpEntity.class。如果是,则问题出在您的启动配置中。在 Eclipse 中,转到 Run > Run Configurations... 并找到主类的 Java 应用程序配置文件(根据屏幕截图,该类应该是包含“Launcher”项目中的 main 方法的类)。在 Classpath 选项卡下,您应该会看到列出的库 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). 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,按 OK,然后返回并再次添加它们(以保证 eclipse元数据是新鲜的)。此外,在“订购和导出”选项卡下,最好勾选所有 jar,这样如果您将 Launcher 作为另一个项目的依赖项包含在内,这些 jar 就会被传递地包含在内。

回答by subro

In my case Maven was not updating dependencies properly. I use mvn clean and then re-updated dependencies then it got fixed.

在我的情况下,Maven 没有正确更新依赖项。我使用 mvn clean 然后重新更新依赖项然后它得到修复。