How to resolve class file for com.google.cloud.Service not found

拜拜、爱过 提交于 2021-02-11 14:13:57

问题


I am Trying to upload JSON data to gcs. As I did not use google cloud previously I started with uploading random String to gcs but I got stuck at the beginning itself while creating a Storage service object

Maven dependency

 <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);

Compile Time Error:

[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.

回答1:


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

solved my issue




回答2:


Did you try to include this dependency in your pom.xml ?

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



回答3:


my understanding is that you can’t upload files to the gcp container using java, and the stack trace is showing that maven failing at compilation time.

Well, You can try 2 things:

1.- Make sure that you Authentication settings are good, You can follow the steps in the link[1]. 2.- Configure you Maven installation according the gcp instructions[2].

[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



来源:https://stackoverflow.com/questions/55833935/how-to-resolve-class-file-for-com-google-cloud-service-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!