How to install & import Java "HttpClient" Library

11,368

You should install a build/dependency management tool such as maven (there are others). Then you will simply need to add the following to your project pom.xml and maven will handle the rest.

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.5.2</version>
</dependency>

If you'd like to manually handle adding the .jar (and it's dependencies) you can specify "CLASSPATH=path/to/your.jar" or when running use "java -cp path/to/your.jar

Share:
11,368

Related videos on Youtube

Admin
Author by

Admin

Updated on May 26, 2022

Comments

  • Admin
    Admin almost 2 years

    So I'm a C++ Programmer who is trying to learn Java in order to write a client-side https receptor application, corresponding to a particular website.

    My Problem:
    I found this wonderful-looking Java library online, called "HttpClient" (See https://hc.apache.org/httpclient-3.x/tutorial.html). Unfortunately, the only way to install the library is manually (download a .zip file with all the .jar files in it). I understand that the include paths are meant to look something like this

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

    But I have no idea how to configure the "CLASSPATH" Environment Variable in order to reflect this (please note that I know HOW to set the variable, just not WHAT to set it to).

    My Question:
    Could someone please explain to me (in laymen's terms) how to download & setup this library onto my Windows 10 PC such that I can implement the above include statements in my code?

    • Admin
      Admin about 8 years
      I apologize in advance for being such a tremendous noob when it comes to Java
    • dantiston
      dantiston about 8 years
      Are you using an IDE like Eclipse?
    • Jiri Tousek
      Jiri Tousek about 8 years
      You need to have it on classpath both when compiling and when running the resulting app. The classpath needs to include the paths to all the needed jars. Compiling and running it using an IDE or a build tool like Maven helps a lot to avoid writing the classpath manually.
  • Admin
    Admin about 8 years
    I tried this, but Maven gave me an error saying it couldn't find the library. Is there somewhere I need to enter the path to my HttpComponents library?