本文介绍了UnknownHostException错误,正在构建Java grpc示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注此grpc教程,并且我什至没有能够通过第一步.第一步是git克隆项目,然后运行

I am following this grpc tutorial and I haven't even been able to make it through the first step. The first step is to git clone the project and then run

cd examples
./gradlew installDist

我被此堆栈跟踪打中

Downloading https://services.gradle.org/distributions/gradle-2.13-bin.zip

Exception in thread "main" java.net.UnknownHostException: services.gradle.org
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
    at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
    at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1513)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
    at org.gradle.wrapper.Download.download(Download.java:44)
    at org.gradle.wrapper.Install$1.call(Install.java:61)
    at org.gradle.wrapper.Install$1.call(Install.java:48)
    at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
    at org.gradle.wrapper.Install.createDist(Install.java:48)
    at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
    at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)

我认为这是一个代理问题,所以我从并打开了文件

I thought that was a proxy issue, so I took some inspiration from this post and opened up the file

gradle/wrapper/gradle-wrapper.properties

并添加了行

systemProp.http.proxyHost=<my proxy>
systemProp.http.proxyPort=<my port>

我也用此替换了distributionUrl行

I also replaced distributionUrl line with this

distributionUrl=http\://services.gradle.org/distributions/gradle-2.13-bin.zip

也就是说,我切换了https-> http.

That is, I switched https --> http.

所有这些之后,我仍然得到相同的堆栈跟踪.

After all of this, I am still getting the same stack trace.

有人建议吗?

我添加了一个

gradle.properties

在主目录中

文件,并添加了字段

file in the home directory, and added the fields

systemProp.http.proxyHost
systemProd.http.proxyPort

systemProp.https.proxyHost
systemProp.https.proxyPort

但是我仍然遇到和以前一样的错误.但是,构建脚本似乎停滞在此行上

but I still got the same error as before. HOWEVER, the build script appeared to stall on this line

Downloading https://services.gradle.org/distributions/gradle-2.13-bin.zip

大约10秒钟左右,然后再失败.所以...进步了吗?

For about 10 seconds or so, before failing. So... progress?

推荐答案

我遇到了同样的问题,终于在2小时后找到了这个解决方案...

I had the same problem and finally found this solution after 2 hours...

转到项目中的文件 gradlew.bat 并更改 DEFAULT_JVM_OPTS 变量,如下所示:

Go to the file gradlew.bat in your project and change DEFAULT_JVM_OPTS variable as below:

set DEFAULT_JVM_OPTS=-Dhttp.proxyHost=YOUR_HOST -Dhttp.proxyPort=PORT -Dhttp.proxyUser=USERNAME -Dhttp.proxyPassword=PASSWORD -Dhttps.proxyHost=YOUR_HOST -Dhttps.proxyPort=PORT -Dhttps.proxyUser=USERNAME -Dhttps.proxyPassword=PASSWORD

然后运行gradlew clean build.

这篇关于UnknownHostException错误,正在构建Java grpc示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 15:19