简体   繁体   English

使用简单的Apache HttpClient Eclipse项目的NoClassDefFoundError

[英]NoClassDefFoundError with simple Apache HttpClient Eclipse project

I'm trying to create a simple Eclipse project to test my code that uses HttpClient code. 我正在尝试创建一个简单的Eclipse项目来测试使用HttpClient代码的代码。

I created a plain Java project in Eclipse, added a Junit4 test case (code below.) I added the httpclient-4.1.3.jar to the Eclipse project that I manually downloaded from Maven Central here and added the jar to the Java build path. 我创建Eclipse的一个普通的Java项目,增加了Junit4测试案例(下面的代码)。我加了httpclient-4.1.3.jar到我手动从Maven的中央下载Eclipse项目在这里 ,并添加了罐子Java构建路径。

When the test runs, I get the following error: 测试运行时,我收到以下错误:

java.lang.NoClassDefFoundError: org/apache/http/params/HttpParams at HttpClientDemo.test(HttpClientDemo.java:13)

HttpClientDemo is simply: HttpClientDemo很简单:

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.junit.Test;


public class HttpClientDemo {
   @Test public void test() {
      HttpClient httpclient = new DefaultHttpClient();
   }
}

Why am I getting this error? 为什么我收到此错误?

Starting from version 4, HttpClient has been split in three parts, under the HttpComponents moniker: Core, the proper Client, and an AsyncClient. 从版本4开始,HttpClient分为三部分,分别在HttpComponents名字:Core,正确的Client和AsyncClient下。 The HttpParams class is now part of HttpComponents Core, so you will also need the specific JAR for that component (supposedly named httpcore-4.1.3.jar ) in order to successfully compile your simple example. HttpParams类现在是HttpComponents Core的一部分,因此您还需要该组件的特定JAR(据称名为httpcore-4.1.3.jar )才能成功编译您的简单示例。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM