java.lang.NoClassDefFoundError: com/google/api/services/storage/model/Bucket$Autoclass

Caused by: java.lang.ClassNotFoundException: com.google.api.services.storage.model.Bucket$Autoclas

I am trying to upload a file to GCS using java client libraries it complies fine i am been hit by java.lang.NoClassDefFoundError: com/google/api/services/storage/model/Bucket$Autoclass error while error ?? Can someone help me in knowing this

0 6 4,591
6 REPLIES 6

The class you mentioned seems to exist and is covered in JavaDoc.  This lends some notion to the idea that you might be missing some JARs in your compilation/execution.  I think to make progress, we are going to have to look in detail at your environment.  Can you describe how you are building in your application?  Are you using Maven or something similar to import dependent JARs?  If yes, please provide as much detail as possible on how you are building your app.

Hi @kolban 

I have download the Jar files and externally included in my framework the jar that I have added are as mentioned below 

1. google-api-services-storage-v1-rev171-1.25.0.jar

2. google-auth-library-credentials-1.14.0.jar

3. google-auth-library-oauth2-http-1.14.0.jar

4. google-cloud-bigquery-2.20.1.jar

5. google-cloud-core-2.9.1.jar

6. google-cloud-core-http-2.9.1.jar

7. google-cloud-storage-2.15.0.jar

8. google-http-client-appengine-1.42.3.jar

9. google-http-client-gson-1.42.3.jar

let me know if you need anything else 

 

I did some hunting around and found the Bucket.Autoclass in this JAR:

https://mvnrepository.com/artifact/com.google.api.grpc/proto-google-cloud-storage-v2/2.17.1-alpha

I think part of the puzzle is when I hear you say you have downloaded JARs ... did you manually download JARs?   Here is my thinking ...

I hear that you want to use Google Cloud Storage APIs ... great.  That means that you need the Google Cloud Storage JARs in your classpath and build environment.  So ... where then do we get those JARs?   I think the anticipation is that you use a dependency manager such as Maven ... if we then look here:

https://mvnrepository.com/artifact/com.google.cloud/google-cloud-storage

we see the Google Cloud Storage dependencies.  If we pick the latest (2.17.x) and drill into that, we see that it has a ton of dependencies by itself.  Included in that is:

com.google.api.grpc » proto-google-cloud-storage-v2

Which is what (I believe) provides the missing class (JAR).  However ... just adding THAT JAR is likely going to fail too ... because there are way more dependencies than just that one JAR.  Are you using Maven or similar tool to download the complete dependency chain?  If not, then I believe that is the problem.

This issue is reproducible when the maven repository https://mvnrepository.com/artifact/com.google.apis/google-api-services-storage/v1-rev171-1.25.0 is used as a dependency in pom.xml file. Upon analysis, we can see that the Bucket$Autoclass is missing in the respective jar file (google-api-services-storage-v1-rev171-1.25.0.jar). 

Did anyone find the solution for this bug?
I have tried in AppEngine to deploy an app with the latest bom library and the problem is changed to this message:

IllegalStateException: You are currently running with version 2.2.0 of google-api-client. You need at least version 1.15 of google-api-client to run version 1.25.0 of the Cloud Storage JSON API library.

My maven config:

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.27.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>


<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.apis/google-api-services-storage -->
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-storage</artifactId>
<version>v1-rev20220705-2.0.0</version>
</dependency>

I ran into this issue and found that the google-cloud-storage library was conflicting with the following dependency:

 

<dependency>
  <groupId>com.google.appengine.tools</groupId>
  <artifactId>appengine-gcs-client</artifactId>
  <version>0.8.3</version>
</dependency>

 

Removing it fixed the problem for me.