java HTTPCLIENT 不存在?网豆

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2216767/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:06:28  来源:igfitidea点击:

HTTPCLIENT does not exist? Netbeans

javanetbeansclasspathhttpclient

提问by Mith

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.jarand httpmime-4.0.1.jar

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

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

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

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. :-(

我仍然无法让它工作......在文件夹“Libraries”中我有: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 在每一个中,它似乎指的是我导入的 jars。仍然得到不存在。:-(

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

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

回答by akf

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

你说的两个jar需要放在Netbeans中项目的classpath下,而不是source目录下。

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.

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

EDIT:

编辑:

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

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

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

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

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;

回答by Droo

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

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

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.

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

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.

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

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

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

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

就其价值而言,除非您使用整个包,否则没有理由导入整个包的内容(即 import package.*)。

回答by EmP

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:

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

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

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

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

Hope you can solve your problems!!!

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

回答by 21stking

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.htmand save it anywhere on your computer.

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

2) Right click on your NetBeans project and select Properties

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

3) On Project Properties Categories, select Libraries

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

4) Click the Add JAR/Folder button

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

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

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

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

6) 现在文件已经安装好了,点击OK就大功告成了。

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

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