我正在使用Netbeans,我已经用Maven创建了java项目。我添加了这种依赖。
<dependency>
<groupId>com.squareup.okhttp</groupId>
<artifactId>okhttp</artifactId>
<version>2.7.2</version>
</dependency>
它工作,我可以导入com.squareup.okhttp。*。在网上看到一些代码后,我意识到许多人正在使用版本3+。我试图将包更改为:
更新我在“com.squareup.okhttp”问题中错误地键入了groupid但在我的代码中它是正确的“com.squareup.okhttp3”。
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.9.0</version>
但我无法导入com.squareup.okhttp3(包com.squareup不存在)。为什么?我是Java语言本身以及支持它的所有IDE和工具的新手。
okhttp3的正确坐标是:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.9.1</version>
</dependency>
请注意,groupId已从com.squareup.okhttp
更改为com.squareup.okhttp3
。
所以,如果你更新你的pom.xml,用我在上面发布的内容替换你对okhttp
所拥有的内容,那么你将能够解析okhttp
类。
为了将来参考,您可以在okhttp
上找到Maven Central文物。
导入只是okhttp3:“import okhttp3”没有com.square。