2016-05-08 11 views
1

次のサイトで提供されているJavaのサンプルを、同じpom.xmlファイルとコードを使用して実行しようとしています。Google BigQueryを使用しており、Compute Engineを使用していますか?

https://cloud.google.com/bigquery/create-simple-app-api

私はそれは必要ないと思ったので、私はのpom.xmlから親要素を取り出しました。

私は以下のpom.xmlを掲載している:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>query</groupId> 
    <artifactId>sample</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>jar</packaging> 


    <repositories> 
    <repository> 
     <id>googleapis</id> 
     <url>https://google-api-client-libraries.appspot.com/mavenrepo</url> 
    </repository> 
    </repositories> 

    <dependencies> 
    <dependency> 
     <groupId>com.google.apis</groupId> 
     <artifactId>google-api-services-bigquery</artifactId> 
     <version>v2-rev265-1.21.0</version> 
    </dependency> 
    <dependency> 
     <groupId>com.google.oauth-client</groupId> 
     <artifactId>google-oauth-client</artifactId> 
     <version>${project.oauth.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.google.http-client</groupId> 
     <artifactId>google-http-client-jackson2</artifactId> 
     <version>${project.http.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.google.oauth-client</groupId> 
     <artifactId>google-oauth-client-jetty</artifactId> 
     <version>${project.oauth.version}</version> 
    </dependency> 
    <dependency> 
     <groupId>com.google.code.gson</groupId> 
     <artifactId>gson</artifactId> 
     <version>2.6</version> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.8.2</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>com.google.truth</groupId> 
     <artifactId>truth</artifactId> 
     <version>0.28</version> 
     <scope>test</scope> 
    </dependency> 
    </dependencies> 

    <properties> 
    <project.http.version>1.21.0</project.http.version> 
    <project.oauth.version>1.21.0</project.oauth.version> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <build> 
     <sourceDirectory>src/main/java</sourceDirectory> 
     <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
     </resource> 
     </resources> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.2</version> 
     <configuration> 
      <source>5</source> 
      <target>5</target> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 

</project> 

Eclipseで実行しているとき、私は私のコンソールで次のエラーを取得する:

May 07, 2016 10:22:54 PM com.google.api.client.googleapis.auth.oauth2.OAuth2Utils runningOnComputeEngine 
WARNING: Failed to detect whether we are running on Google Compute Engine. 
java.net.SocketException: Network is unreachable: connect 
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) 
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source) 
    at java.net.PlainSocketImpl.connect(Unknown Source) 
    at java.net.SocksSocketImpl.connect(Unknown Source) 
    at java.net.Socket.connect(Unknown Source) 
    at sun.net.NetworkClient.doConnect(Unknown Source) 
    at sun.net.www.http.HttpClient.openServer(Unknown Source) 
    at sun.net.www.http.HttpClient.openServer(Unknown Source) 
    at sun.net.www.http.HttpClient.<init>(Unknown Source) 
    at sun.net.www.http.HttpClient.New(Unknown Source) 
    at sun.net.www.http.HttpClient.New(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) 
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:93) 
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981) 
    at com.google.api.client.googleapis.auth.oauth2.OAuth2Utils.runningOnComputeEngine(OAuth2Utils.java:86) 
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.detectEnvironment(DefaultCredentialProvider.java:183) 
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredentialUnsynchronized(DefaultCredentialProvider.java:110) 
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:91) 
    at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213) 
    at sample.querysample.createAuthorizedClient(querysample.java:33) 
    at sample.querysample.main(querysample.java:113) 

May 07, 2016 10:22:54 PM com.google.api.client.googleapis.auth.oauth2.OAuth2Utils runningOnComputeEngine 
WARNING: Failed to detect whether we are running on Google Compute Engine. 
java.net.SocketException: Network is unreachable: connect 
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) 
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source) 
    at java.net.PlainSocketImpl.connect(Unknown Source) 
    at java.net.SocksSocketImpl.connect(Unknown Source) 
    at java.net.Socket.connect(Unknown Source) 
    at sun.net.NetworkClient.doConnect(Unknown Source) 
    at sun.net.www.http.HttpClient.openServer(Unknown Source) 
    at sun.net.www.http.HttpClient.openServer(Unknown Source) 
    at sun.net.www.http.HttpClient.<init>(Unknown Source) 
    at sun.net.www.http.HttpClient.New(Unknown Source) 
    at sun.net.www.http.HttpClient.New(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) 
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:93) 
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981) 
    at com.google.api.client.googleapis.auth.oauth2.OAuth2Utils.runningOnComputeEngine(OAuth2Utils.java:86) 
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.detectEnvironment(DefaultCredentialProvider.java:183) 
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredentialUnsynchronized(DefaultCredentialProvider.java:110) 
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:91) 
    at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213) 
    at sample.querysample.createAuthorizedClient(querysample.java:33) 
    at sample.querysample.main(querysample.java:113) 

May 07, 2016 10:22:54 PM com.google.api.client.googleapis.auth.oauth2.OAuth2Utils runningOnComputeEngine 
WARNING: Failed to detect whether we are running on Google Compute Engine. 
java.net.SocketException: Network is unreachable: connect 
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) 
    at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) 
    at java.net.AbstractPlainSocketImpl.connect(Unknown Source) 
    at java.net.PlainSocketImpl.connect(Unknown Source) 
    at java.net.SocksSocketImpl.connect(Unknown Source) 
    at java.net.Socket.connect(Unknown Source) 
    at sun.net.NetworkClient.doConnect(Unknown Source) 
    at sun.net.www.http.HttpClient.openServer(Unknown Source) 
    at sun.net.www.http.HttpClient.openServer(Unknown Source) 
    at sun.net.www.http.HttpClient.<init>(Unknown Source) 
    at sun.net.www.http.HttpClient.New(Unknown Source) 
    at sun.net.www.http.HttpClient.New(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) 
    at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source) 
    at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:93) 
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981) 
    at com.google.api.client.googleapis.auth.oauth2.OAuth2Utils.runningOnComputeEngine(OAuth2Utils.java:86) 
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.detectEnvironment(DefaultCredentialProvider.java:183) 
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredentialUnsynchronized(DefaultCredentialProvider.java:110) 
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:91) 
    at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213) 
    at sample.querysample.createAuthorizedClient(querysample.java:33) 
    at sample.querysample.main(querysample.java:113) 

Exception in thread "main" java.io.IOException: The Application Default Credentials are not available. They are available if running on Google App Engine, Google Compute Engine, or Google Cloud Shell. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information. 
    at com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:98) 
    at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213) 
    at sample.querysample.createAuthorizedClient(querysample.java:33) 
    at sample.querysample.main(querysample.java:113) 

私はCompute Engineのを使用する予定はありません、 Google BigQueryだけです

ありがとうございます。

+2

この部分は読んでいますか?スレッド "main"の例外java.io.IOException:アプリケーションデフォルトの資格情報は使用できません。 Google App Engine、Google Compute Engine、Google Cloud Shellで実行している場合に利用できます。それ以外の場合は、環境変数GOOGLE_APPLICATION_CREDENTIALSを定義して、資格を定義するファイルを指定する必要があります。詳細については、[https://developers.google.com/accounts/docs/application-default-credentials](https://developers.google.com/accounts/docs/application-default-credentials)を参照してください。 –

+2

もちろん、コンソールにサービスアカウントキーを作成してローカルに保存し、その環境変数を.jsonファイルで指定するだけです。あなたはこれを解決できましたか? – Adam

答えて

2

これはもはや関連性がないと思うが、私の場合、IDEを再起動することで問題が解決されている。私はWindowsとIdeaをIDEとして使用しています。問題は、システム変数にGOOGLE_APPLICATION_CREDENTIALSを追加する前にIDEを実行していたことです。コマンドラインの実行中にシステム変数を追加すると、コマンドラインを再起動してシステム変数を有効にする必要があります

関連する問題