How to import okhttp in a standard java program?

Viewed 2540

I am trying to import the okhttp package in a java program, but I have not been able to find how to do it.

For now, I have downloaded the package on my computer (from the following git hub link : https://github.com/square/okhttp) but I do not understand how to import the package in my program.

Any suggestion on how to use this package?

1 Answers

Download Dependency

You can download the jar file from maven central.

download jar

Add to Project Classpath

Then you need to add it to your classpath.

Shell

If you're compiling from the terminal place your okhttp.jar file in the same directory as your Java class. You can then run the following command

javac -cp okhttp-2.7.5.jar MyClass.java

You need to replace okhttp-2.7.5.jar with the actual name of the okhttp jar, and replace MyClass.java with the actually name of your Java file

Eclipse

  1. Right click on project
  2. Build Path...
  3. Configure Build Path....
  4. Add External Jar
  5. Select the jar file

right click add external jar

The method outlined above is the simplest way to add dependencies to a project. However, there are specific technologies such as Ant, Maven, and Gradle which allow you to include dependencies through XML or other DSL's

Related