• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Eclipse Error: The import org.apache.commons.httpclient cannot be resolved

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I keep getting the error:
"The import org.apache.commons.httpclient cannot be resolved"
and don't know how to resolve it. Help would be much appreciated, as I am clearly missing something stupid.

Here is what I have done so far:
-- Downloaded the httpcomponents-client-4.0-bin-with-dependencies from Jakarta / Apache, extracted it and put the JAR's into /jre/lib/ext
... So it should find it, right? (It is accessing the correct JRE, as found in Eclipse->Preferences->Java ... )
-- Added them to the build path (Properties -> Build path -> Add external Jars)
-- Followed advice on this page: http://blog.sherifmansour.com/?p=207,
.... including Clean, removing and re-adding them, F5 to refresh. When I remove then, Eclipse changes the length of the wiggly red line under them, so it is clearly finding something.

But I keep getting the "cannot be resolved" error for these imports:
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.params.HttpMethodParams;

Any help would be GREATLY appreciated, as the next step is to beat my head with a stick.
//
 
Marshal
Posts: 77285
371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you unzipped the files. If you do, you find 6 .jar files in the "lib" directory. Did you click them on the "add external jars" page?

Moving to the IDEs forum.
 
D Swart
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, thanks.

So some progress. ... but still no luck. I browsed the packages, and changed the import statements - see code below:

Iget the error:
Access restriction: The type HttpClient is not accessible due to restriction on required library C:\Program Files\Java\jdk1.6.0_02\jre\lib\ext\httpclient-4.0.jar

thanks.

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JRE comes with its own HttpClient?!
 
D Swart
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know, but don't think an internal conflict is the problem: I have tried it on a friend's machine, and it works fine, so it must be a setting within my configuration. A quick google suggests that the httpclient I'm trying to use, http://hc.apache.org/httpclient-3.x/, is not conflicting. I wonder if it is possible that it is somehow being included twice?

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you should find out. You say it's not an "internal conflict", then go on to say that it might be being included twice--that's a conflict if I ever heard of one.
 
Marshal
Posts: 27540
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The type HttpClient is not accessible due to restriction on required library C:\Program Files\Java\jdk1.6.0_02\jre\lib\ext\httpclient-4.0.jar


Whose idea was it to put that jar into the extensions directory? That's usually a quick and dirty way to get things going for people who don't know how to set their classpath, and it often isn't a good idea for various reasons. This appears to be one of those times. Get it out of there.
 
D Swart
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul - moving them out helped. I removed them to a different directory, and then readded them using "add external JARS", and the errors disappear with the includes. It now it tells me:
Cannot instantiate the type HttpClient
in line 12 above (The "new HttpClient();" statement.)

A quick google says this comes from trying to instantiate an abstract class. But this code is taken directly from the tutorial at http://hc.apache.org/httpclient-3.x/tutorial.html and should work as is.

Any ideas?

Thanks in advance for help.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the correct documentation for the version you're using.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic