views:

979

answers:

2

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

+3  A: 

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;
akf
How do I do that? ... :-$
Mith
OK - Within Projects in netbeans, I managed to add httpclient, etc to "Libraries".I am still getting "does not exist"...
Mith
Can you for your help on this! It is appreciated.I still cannot get it to work though...Within the folder "Libraries" I have:apache-mime4j0.6.jarcommons-codec-1.3.jarcommons-logging-1.1.1.jarhttpclient-4.0.1.jarhttpcore-4.0.1.jarhttpmime-4.0.1.jarFor the java file properties it has:compile classpathruntime classpathboot classpathIn each of those, it seems to refer to the jars I have imported. Still getting does not exist. :-(
Mith
can you = thank you!
Mith
Yes that seems to fix that problem! Wow, thank you!I have been following this resource and it must be out of date: http://hc.apache.org/httpclient-3.x/tutorial.htmlI am trying: HttpClient client = new HttpClient();But for HttpClient(); it gives that it is "abstract, cannot be instantiated".
Mith
Ah, the tutorial is for httpclient 3. Dang!
Mith
Thank you for all your help. Very much appreciated!
Mith
A: 

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

Droo