java - 如何解决找不到 com.google.cloud.Service 的类文件

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

我正在尝试将 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.

最佳答案

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

解决了我的问题

关于java - 如何解决找不到 com.google.cloud.Service 的类文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55833935/

相关文章:

java - 判断二叉树的节点数是否为奇数

maven - Bamboo 阶段和 Maven 生命周期

java - 使用 spring-boot-starter-data-jpa 时出现 Hibernate-core 错误

model - { "error": "Serving signature name: "serving_default"not found in signature def"}

java - 如何从 DataStore 切换(迁移)到 Google Cloud SQL?

java - 合并从类型 <?扩展号码>

python - 向 Google Cloud Storage 存储桶提供用户项目

mysql - 通过私有(private) IP 拒绝 Google Cloud MySQL 访问,但允许通过公共(public) IP 访问

java - 第二次赋值后重置静态变量

java - 如何在tomcat上运行vaadin项目?