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

问题描述 投票:0回答:3

我正在尝试将JSON数据上传到gcs。由于我之前没有使用谷歌云,所以我开始将随机字符串上传到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.
java maven google-cloud-platform google-cloud-storage
3个回答
1
投票
<dependency>
 <groupId>com.google.cloud</groupId>
 <artifactId>google-cloud</artifactId>
 <version>0.47.0-alpha</version>
</dependency>

解决了我的问题


0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.