Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import org.apache.commons.httpclient.*

Tags:

java

I use a code that imports the following package:

import org.apache.commons.httpclient.*;

I use eclipse. I went to http://hc.apache.org/downloads.cgi & I downloaded the Jar files, I added them to my project. Still eclipse making an error for this.

Exception in thread "main" java.lang.Error: Unresolved compilation problems: HttpClient cannot be resolved to a type

What is the problem?

like image 965
Jury A Avatar asked Mar 10 '26 20:03

Jury A


2 Answers

If you are using the latest (4.x) version of these modules, they have been refactored a lot. For example, the package name is now org.apache.http.client. Old sample code will have to be modified. Look at the Javadocs and the Quickstart for the new project.

The (discouraged) alternative would be to get the old (3.x) version.

like image 197
Thilo Avatar answered Mar 13 '26 08:03

Thilo


I would recommend using Maven for managing your 3rd party dependencies. It takes care of jar files & all related dependencies.

The maven dependency for httpclient is:

 <dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.2.1</version>
    <scope>compile</scope>
  </dependency>
like image 34
Reimeus Avatar answered Mar 13 '26 08:03

Reimeus