Listing buckets with Google Cloud Storage resulting in NoSuchMethodError, Java AppEngine

Jonathan Laliberte :

Trying to just list the buckets in my Google Cloud Storage project but can't quite understand why i keep getting the following error:

java.lang.NoSuchMethodError: com.google.api.services.storage.model.Bucket.getIamConfiguration()Lcom/google/api/services/storage/model/Bucket$IamConfiguration;

I'm testing it with the following servlet:

package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;

@WebServlet("/Test")
public class Test extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public Test() {
        super();
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        Storage storage = StorageOptions.getDefaultInstance().getService();
        for (Bucket bucket : storage.list().iterateAll()) { //this line is giving the error
            response.getWriter().write(bucket.getName());
        }
    }
}

In my pom i have:

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

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

The former dependency isn't required for this specific example but i need it for another part of the application, I suspect this might be where the problem lies. Any ideas what could be going wrong?

Jonathan Laliberte :

Found the problem. I was getting a NoSuchMethodError because apparently the library needed wasn't included in the project even though it was specified as a maven dependency. Some kind of mismatch between the libraries on the development server and the libraries on the production server.

The solution in Eclipse was to remove all the revelant Google libraries and add them again by right clicking on the project > Build Path > Configure Build Path... > Add Library... > Google Cloud Platform Libraries > Select "App Engine API" & "Cloud Storage".

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=151847&siteId=1