HTTPCLIENT 不存在?网豆

发布于 2024-08-20 08:43:11 字数 662 浏览 9 评论 0原文

我正在尝试导入:

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 文件相同的文件夹中。

有什么想法吗?

我仍然无法让它工作...在文件夹“Libraries”中我有: apa​​che-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 文件属性,它具有: 编译类路径 运行时类路径 启动类路径 在每一个中,它似乎引用了我导入的 jar。仍然得到不存在。 :-(

我也尝试在 Eclipse 中执行此操作,现在这些文件出现在“参考库”中,但它仍然不起作用。哈哈

I am trying to import:

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

But I am being told these do not exist?

I downloaded:
httpclient-4.0.1.jar and httpmime-4.0.1.jar

... and placed these in the same folder as my .java files that are trying to use httpclient.

Any ideas?

I still cannot get it to work... Within the folder "Libraries" I have: 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 For the java file properties it has: compile classpath runtime classpath boot classpath In each of those, it seems to refer to the jars I have imported. Still getting does not exist. :-(

I have tried to do this in Eclipse too and now those files appear in "Referenced libraries" however it still doesn't work. lol

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

英雄似剑 2024-08-27 08:43:11

你提到的两个jar需要放在Netbeans中项目的类路径中,而不是放在源目录中。

在 Mac 上的 Netbeans 6.7.1 中,在“项目”选项卡中,您可以右键单击该项目并选择“属性”。这将打开项目属性对话框。在那里,从左侧的树中选择库项目。从那里,在“编译”视图中选择“添加 Jar/文件夹”。要将 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;

The two jars you have mentioned need to be placed in the classpath of the project in Netbeans, not in the source directory.

In my Netbeans 6.7.1 on Mac, in the Prjects tab, you cna right click on the project and select Properties. That will bring up the project properties dialog. In there, choose the libraries item from the tree on the left. From there, choose the Add Jar/Folder in the Compile view. To add the jar to your project, use the chooser to locate it and then select it.

EDIT:

I have just downloaded the HTTPClient package and I think I see the problem:

in 4.0.1, the package structure is not as you have it defined. Instead of:

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

use:

import org.apache.http.client.*;
import org.apache.http.client.methods.*;
import org.apache.http.client.params.HttpMethodParams;
几味少女 2024-08-27 08:43:11

在 Eclipse 中,按 Ctrl + Shift + O 来组织导入。这将查找类路径上的所有未知类并尝试导入它们。您还可以将光标放在类名称上,然后按 Ctrl + Shift + M 尝试导入该单个类。这有时对于类名冲突很有帮助(即,如果两个包都有一个 HttpClient 类,您可以单击所需的类)。

如果 jar 位于引用库中,那么它们应该位于您的类路径中。您可以通过右键单击项目并选择“构建路径”>“构建路径”之类的内容来验证这一点。配置构建路径,然后单击库选项卡。

另外,默认情况下您可能会自动选择构建,但如果没有,则需要构建项目。您可能还想尝试清除构建路径并重新构建它。我见过我的 Eclipse 有几次不同步,这解决了它,尽管有点侥幸。

如果您使用 Maven,如果您的依赖范围不正确(即运行时或测试与编译),有时会发生这种情况。

无论如何,除非您使用整个包,否则没有理由导入整个包的内容(即 import package.*)。

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.*).

不喜欢何必死缠烂打 2024-08-27 08:43:11

看来 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

希望你能解决你的问题!

It seems that HttpClient has changed his sintaxis from 3 to 4 version... I had same problems that all of you trying to import packages until I found this example:

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

This is sample is Android oriented but works on any Java Application!!! Im using netbeans 6.9.1, httpclient-4.1.1.jar, commons-codec-1.4.jar and commons-logging-1.1.1.jar

Hope you can solve your problems!!!

倒数 2024-08-27 08:43:11

遇到了同样的问题,我设法找到了解决方案。如下:

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

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

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

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

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

6) 现在文件已安装,单击“确定”即可完成。

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

Had the same problem and i managed to get the solution. Here it is:

1) Download the org.apache.commons.httpclient.jar.zip file from
http://www.java2s.com/Code/Jar/o/Downloadorgapachecommonshttpclientjar.htm
and save it anywhere on your computer.

2) Right click on your NetBeans project and select Properties

3) On Project Properties Categories, select Libraries

4) Click the Add JAR/Folder button

5) Now browse to the file location where you saved your downloaded org.apache....jar.zip
file and click open button.

6) Now the file has been installed, click OK and you are done.

Note that this might require you to restart your netbeans IDE.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文