如何解析com.google.cloud.Service的类文件

时间:2019-04-24 15:44:15

标签: java maven google-cloud-platform google-cloud-storage

我正在尝试将JSON数据上传到gcs。由于我以前没有使用过Google Cloud,因此我开始将随机String上传到gcs,但是在创建存储服务对象时却陷入了起步阶段

Maven依赖

 <dependency>
   <groupId>com.google.cloud</groupId>
   <artifactId>google-cloud-storage</artifactId>
   <version>1.70.0</version>
 </dependency>


import com.google.cloud.storage.*;
Storage storage = StorageOptions.getDefaultInstance().getService();
    BlobId blobId = BlobId.of("bucket_name", "test_upload/test.txt");
    BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
    Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
    System.out.println(blob);

编译时错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project gcshelper: Compilation failure: Compilation failure: 
ERROR] /Users/v3/gcshelper/src/main/java/com/tv/gcs/GcsTest.java:[16,41] cannot access com.google.cloud.ServiceOptions [ERROR] class file for com.google.cloud.ServiceOptions not found [ERROR] /Users/v3/gcshelper/src/main/java/com/tv/gcs/GcsTest.java:[19,28] cannot access com.google.cloud.Service [ERROR] class file for com.google.cloud.Service not found [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging.

3 个答案:

答案 0 :(得分:1)

<dependency>
 <groupId>com.google.cloud</groupId>
 <artifactId>google-cloud</artifactId>
 <version>0.47.0-alpha</version>
</dependency>

解决了我的问题

答案 1 :(得分:0)

您是否尝试在pom.xml中包含此依赖项?

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-core</artifactId>
    <version>1.70.0</version>
</dependency> 

答案 2 :(得分:0)

我的理解是您无法使用Java将文件上传到gcp容器,并且堆栈跟踪显示maven在编译时失败。

好吧,您可以尝试两种方法:

1.-确保身份验证设置正确,您可以按照链接[1]中的步骤进行操作。 2.-按照gcp说明[2]配置Maven安装。

[1] https://cloud.google.com/docs/authentication/production#auth-cloud-implicit-java [2] https://cloud.google.com/appengine/docs/standard/java/tools/maven#setting_up_maven