2016-11-05 32 views
0

我想在MAVEN中使用GSON將JSON轉換爲JAVA對象,我遵循YouTube視頻的指導 - https://www.youtube.com/watch?v=Vqgghm9pWe0,但是在主類中發生的錯誤是錯誤 - package com.squareup。 okhttp3不存在。代碼如下:如何解決錯誤 - 包com.squareup.okhttp3不存在?

的Java

package com.codebeasty.json; 
import com.squareup.okhttp3.OkHttpClient; 

public class Main { 

    private static OkHttpClient client = new OkHttpClient(); 
    public static void main (String [] args) 
    { 
    } 

} 

我甚至把在依賴於pom.xml中:

<dependencies> 
<dependency> 
<groupId>com.squareup.okhttp3</groupId> 
<artifactId>okhttp</artifactId> 
<version>3.4.2</version> 
</dependency> 

<dependency> 
<groupId>com.google.code.gson</groupId> 
<artifactId>gson</artifactId> 
<version>2.8.0</version> 
</dependency> 

</dependencies> 

我不明白爲什麼它不承認com.squareup 。有什麼額外的我可能需要下載?我已經從這個網站下載了JAR - http://square.github.io/okhttp/,並且試圖用依賴項來構建項目。請幫助:(

+0

安裝下載的,我希望你在你的IDE版本(NetBeans)得到這個錯誤。你試試使用命令行編譯代碼?你可以導航到你的項目。做「mvn clean install」。看起來像自動安裝依賴關係功能沒有啓用。 。 – Eranda

回答

0

Maven repo有最新版本3.4.1。在POM試圖改變版本或在本地使用

mvn install:install-file -Dfile=path/to/okhttp-3.4.2.jar -DgroupId=com.squareup.okhttp3 -DartifactId=okhttp -Dversion=3.4.2 -Dpackaging=jar 
+0

感謝您的回答,下載後的版本會有效果嗎? –

+0

後面的版本3.4.1?不知道請檢查返工兼容性。 – Shashank

+0

我需要安裝任何東西才能使okhttp wor K +和我有版本3.4.2 –

相關問題