1

我正在尝试导入:

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;

但有人告诉我这些不存在?

我下载了: httpclient-4.0.1.jarhttpmime-4.0.1.jar

...并将它们放在与我尝试使用 httpclient 的 .java 文件相同的文件夹中。

有任何想法吗?

我仍然无法让它工作......在“图书馆”文件夹中我有:apache-mime4j0.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 对于它具有的java文件属性: compile classpath runtime classpath boot classpath 在每一个中,似乎都指的是我已经导入的jar。仍然得到不存在。:-(

我也尝试在 Eclipse 中执行此操作,现在这些文件出现在“引用的库”中,但它仍然无法正常工作。哈哈

4

4 回答 4

4

您提到的两个jar需要放在Netbeans中项目的classpath中,而不是放在源目录中。

在 Mac 上的 Netbeans 6.7.1 中,在项目选项卡中,您可以右键单击项目并选择属性。这将打开项目属性对话框。在那里,从左侧的树中选择库项目。从那里,在 Compile 视图中选择 Add Jar/Folder。要将 jar 添加到您的项目中,请使用选择器找到它,然后选择它。

编辑:

我刚刚下载了 HTTPClient 包,我想我看到了问题:

在 4.0.1 中,包结构与您定义的不同。代替:

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;

利用:

import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.client.params.HttpMethodParams;
于 2010-02-07T12:51:18.773 回答
0

In Eclipse, press Ctrl + Shift + O to organize your imports. This will look for all unknown classes on the classpath and try to import them. You can also place your cursor on a class name and press Ctrl + Shift + M to attempt to import that single class. This is sometimes helpful for class name collision (i.e. if two packages have a HttpClient class, you can click on the desired class).

If the jars are in Referenced Libraries, then they should be on your classpath. You can verify this by right clicking the project and selecting something like Build Path > Configure Build Path, then click the libraries tab.

Also, you probably have build automatically selected by default, but if you don't, you'll need to build your project. You may also want to attempt to clear the build path and re-build it. I've seen my Eclipse get out of synch a few times and this fixed it, albeit somewhat of a fluke.

If you're using Maven, this sort of thing can sometimes occur if you have an incorrect dependency scope (i.e. runtime, or test vs. compile).

For what it's worth, unless you're utilizing the entire package, there is no reason to import an entire package's contents (i.e. import package.*).

于 2010-02-07T16:28:55.960 回答
0

似乎 HttpClient 已经将他的 sintaxis 从 3 版本更改为 4 版本......在我找到这个例子之前,我遇到了同样的问题,你们所有人都在尝试导入包:

http://w3mentor.com/learn/java/android-development/android-http-services/example-of-http-get-request-using-httpclient-in-android/

这是面向 Android 的示例,但适用于任何 Java 应用程序!!!我正在使用 netbeans 6.9.1、httpclient-4.1.1.jar、commons-codec-1.4.jar 和 commons-logging-1.1.1.jar

希望能解决你的问题!!!

于 2011-07-05T10:34:04.917 回答
0

有同样的问题,我设法得到了解决方案。这里是:


1) 从http://www.java2s.com/Code/Jar/o/Downloadorgapachecommonshttpclientjar.htm下载 org.apache.commons.httpclient.jar.zip 文件 并将其保存在计算机上的任何位置。

2) 右键单击​​您的 NetBeans 项目并选择属性

3) 在项目属性类别上,选择

4) 单击添加 JAR/文件夹按钮

5) 现在浏览到保存下载的 org.apache....jar.zip 文件的文件位置,然后单击打开按钮。

6) 现在文件已经安装好了,点击确定就完成了。

请注意,这可能需要您重新启动 netbeans IDE。

于 2013-04-10T09:07:17.810 回答