本文介绍了HttpClient NoClassDefFoundError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从HttpClient 4.0.1运行示例应用程序。它是示例部分中的ClientMultiThreadedExecution.java文件。我将这些文件放在类路径中: apache-mime4j-0.6.jar ; commons-codec-1.3.jar ; 共享记录-1.1.1.jar ; 的HttpClient-4.0.1.jar ; httpcore-4.0.1.jar ; httpmime-4.0.1.jar ,文件正确编译。在运行时我收到以下错误:

I am trying to run a sample application from HttpClient 4.0.1. It is the file ClientMultiThreadedExecution.java from the examples section. I put in these files in the classpath: apache-mime4j-0.6.jar;commons-codec-1.3.jar;commons-logging-1.1.1.jar;httpclient-4.0.1.jar;httpcore-4.0.1.jar;httpmime-4.0.1.jar and the file compiles correctly. At runtime I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/client/methods/HttpUriRequest
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.methods.HttpUriRequest
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

我错过了引用吗?这似乎是一个类路径错误,但我无法弄清楚要包含哪个jar文件?提前感谢您的帮助。

Am I missing a reference? It seems like a classpath error but I can't figure out which jar file to include? Thank you in advance for your help.

推荐答案

此异常表示运行时中缺少提到的类 classpath。

This exception tells that the mentioned class is missing in the runtime classpath.

有几种方法可以指定运行时类路径,具体取决于您执行程序的方式。由于一个体面的IDE从你手中透明地接受了这一切,我打赌你在命令提示符下运行它。

There are several ways to specify the runtime classpath, depending on how you're executing the program. Since a decent IDE takes this all transparently from your hands, I bet that you're running it in a command prompt.

如果您通过 java.exe -jar 将其作为JAR文件运行或双击该文件,则您需要在JAR的 MANIFEST.MF 文件的 Class-Path 条目中指定类路径。请注意%CLASSPATH%环境变量和 -cp -classpath 参数被忽略

If you're running it as a JAR file by java.exe -jar or doubleclicking the file, then you need to specify the classpath in the Class-Path entry of the JAR's MANIFEST.MF file. Note that the %CLASSPATH% environment variable and -cp and -classpath arguments are ignored whenever you execute a JAR.

如果您通过 java.exe ,然后你需要在 -cp -classpath中指定它参数。请注意,每当您使用此参数时,%CLASSPATH%环境变量被忽略

If you're running it as a "plain vanilla" Java application by java.exe, then you need to specify it in the -cp or -classpath argument. Note that whenever you use this argument, the %CLASSPATH% environment variable is ignored.

无论哪种方式,类路径都应该存在一个(半)冒号分隔的JAR文件路径(绝对路径或相对于当前工作目录)。例如

Either way, the classpath should exist of a (semi)colonseparated string of paths to JAR files (either absolute paths or relative to current working directory). E.g.

java -cp .;/path/to/file1.jar;/path/to/file2.jar com.example.MyClass

(如果您使用的是Unix / Linux,请使用冒号而不是分号作为路径分隔符)

(if you're on Unix/Linux, use colon instead of semicolon as path separator)

这篇关于HttpClient NoClassDefFoundError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 15:39