如何在标准 java 程序中导入 okhttp?

How to import okhttp in a standard java program?

我正在尝试在 java 程序中导入 okhttp 包,但我一直无法找到如何操作。

现在,我已经在我的电脑上下载了这个包(来自以下 git hub link : https://github.com/square/okhttp)但是我不知道如何将这个包导入我的程序。

关于如何使用这个包有什么建议吗?

下载依赖

您可以从 maven central 下载 jar 文件。

添加到项目类路径

然后你需要将它添加到你的class路径中。

Shell

如果您从终端编译,请将您的 okhttp.jar 文件放在与您的 Java class 相同的目录中。然后你可以运行下面的命令

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

日食

  1. 右键单击项目
  2. 构建路径...
  3. 配置构建路径....
  4. 添加外部 Jar
  5. Select 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