2017-06-15 135 views
0

我刚刚开始在谷歌云平台上。我在云端控制台上创建了一个帐户和一个项目。我试图运行一些提供的示例应用程序。 我开始在提供云存储的示例应用程序:无法运行谷歌云平台示例应用程序

https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/storage/cloud-client

我已经安装了Apache Maven的3.5.0我的电脑上。 我紧跟在链接提供的步骤,即我给下面的命令:

mvn clean package -DskipTests 

然后

mvn exec:java -Dexec.mainClass=com.example.storage.QuickstartSample -Dexec.args="my-bucket-name" 

第一命令成功。但是,第二个命令失败了。 我得到了以下错误:

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 01:06 min 
[INFO] Finished at: 2017-06-15T18:27:55+05:30 
[INFO] Final Memory: 15M/172M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli) on project storage-google-cloud-samples: An exception occured while executing the Java class. connect timed out -> [Help 1] 

现在,我在那里上运行此命令的计算机的背后,是一个代理。然而,我的代理设置已经在conf/settings.xml文件中设置,当我运行第一个命令时,它也成功下载了一些软件包,所以我不确定是否是由于某些代理问题导致的,但是要检查,我在另一台机器上尝试了它,它不在代理之后。

我给出了相同的两个命令。第一个成功,第二次失败,有如下(不同的)错误:

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 01:02 min 
[INFO] Finished at: 2017-06-15T18:22:31+05:30 
[INFO] Final Memory: 13M/32M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:java (d 
efault-cli) on project storage-google-cloud-samples: An exception occured while 
executing the Java class. 401 Unauthorized -> [Help 1] 

所以我的疑问是:

  1. 可能是什么在第一种情况下错误的原因是什么?这与代理设置有关吗?如果是,那么我应该在哪里/如何指定设置?

  2. 在第二种情况下,我不支持任何代理服务器时,可能导致错误的原因是什么?

  3. 我错过了一些步骤吗?另外,如果你看看这个示例应用程序的源代码,只有一个基本上创建一个存储桶的文件。该存储桶作为参数从命令行传递。现在,按照我的理解,首先需要在云端控制台中创建一个项目来创建任何资源。那么这个桶将在哪里创建?因为在这里我们不应该指定要创建这个桶的项目ID吗?

+0

有没有关于此的谷歌群组? –

+0

按照链接https://cloud.google。com/support/docs/community, 他们推荐技术问题的堆栈溢出 –

回答

1

TL; DR - 你缺少凭据,示例依赖于调用所需的谷歌云API。在使用任何客户端库使用Google Cloud API时,建议使用Application Default Credentials

加长版

的例子依赖于Application Default Credentials(您使用的GitHub库的as explained in the README.md)。

How the Application Default Credentials work

You can get Application Default Credentials by making a single client library call. The credentials returned are determined by the environment the code is running in. Conditions are checked in the following order:

  1. The environment variable GOOGLE_APPLICATION_CREDENTIALS is checked. If this variable is specified it should point to a file that defines the credentials. The simplest way to get a credential for this purpose is to create a Service account key in the Google API Console:

    a. Go to the API Console Credentials page .

    b. From the project drop-down, select your project.

    c. On the Credentials page, select the Create credentials drop-down, then select Service account key.

    d.From the Service account drop-down, select an existing service account or create a new one.

    e. For Key type, select the JSON key option, then select Create. The file automatically downloads to your computer.

    f. Put the *.json file you just downloaded in a directory of your choosing. This directory must be private (you can't let anyone get access to this), but accessible to your web server code.

    g. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file downloaded.

  2. If you have installed the Google Cloud SDK on your machine and have run the command gcloud auth application-default login , your identity can be used as a proxy to test code calling APIs from that machine.

  3. If you are running in Google App Engine production, the built-in service account associated with the application will be used.

  4. If you are running in Google Compute Engine production, the built-in service account associated with the virtual machine instance will be used.

  5. If none of these conditions is true, an error will occur.