我有问题。
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
public class qq {
public static void main(String[] args) throws UnsupportedEncodingException, IOException {
HttpClient httpclient = new DefaultHttpClient();
// HttpPost httppost = new HttpPost("http://192.168.0.102/uploadtest/upload_photo");
System.out.println("aaaa");
}
}
文件manifest.mf:
Manifest-version: 1.0 Main-Class: qq操作系统debian 8 java版本: java版“1.8.0_111” Java(TM)SE运行时环境(版本1.8.0_111-b14) Java HotSpot(TM)64位服务器VM(版本25.111-b14,混合模式)
和
javac -cp ./lib/httpclient-4.2.5.jar:./lib/httpcore-4.4.5.jar:./lib/httpmime-4.2.5.jar:./lib/commons-logging-1.2.jar qq.java jar cfm test.jar manifest.mf qq.class
没问题,没有错误,退出代码 - 0。
我试试:
# java -jar test.jar Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/impl/client/DefaultHttpClient at qq.main(qq.java:18) Caused by: java.lang.ClassNotFoundException: org.apache.http.impl.client.DefaultHttpClient at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 1 more
如何解决这个问题?
答案 0 :(得分:0)
我建议您使用 Maven 或 Gradle ,因为系统会自动加载。\ / p>
<强>的Maven:强>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
</dependency>
<强>摇篮:强>
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.1'