NoClassDefFoundError: com/google/api/client/extensions/appengine/http/UrlFetchTransport?

坚强是说给别人听的谎言 提交于 2020-01-16 18:40:33

问题


I have a web service on google app engine and I am trying to read a file from the google cloud store from the web service. This is the code I am using:

public static byte[] readFile2(String bucket, String filepath) throws IOException {
    GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());
    GcsFilename fileName = new GcsFilename(bucket, filepath);
    logger.warning(fileName.toString() + "<br>");
    logger.warning(String.format("/gs/%s/%s", fileName.getBucketName(), fileName.getObjectName()));
    int fileSize = (int) gcsService.getMetadata(fileName).getLength();
    ByteBuffer result = ByteBuffer.allocate(fileSize);
    try (GcsInputChannel readChannel = gcsService.openReadChannel(fileName, 0)) {
        readChannel.read(result);
    }
    return result.array();
}

and am invoking this with

writer.write(new String(readFile2("myBucket", "my/path/to/file.sql")));

However when I try to run the service I get

java.lang.NoClassDefFoundError: com/google/api/client/extensions/appengine/http/UrlFetchTransport
at com.google.appengine.tools.cloudstorage.oauth.OauthRawGcsServiceFactory.<clinit>(OauthRawGcsServiceFactory.java:29)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createRawGcsService(GcsServiceFactory.java:42)
at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService(GcsServiceFactory.java:34)
at ...........................CloudLookupServlet.readFile2(CloudLookupServlet.java:69) -> first line of readFile2
...

I have the following jars in my war:

appengine-api-labs.jar
appengine-api-stubs.jar
appengine-api.jar
appengine-gcs-client-0.3.9.jar
appengine-local-runtime-shared.jar
commons-lang3-3.2.jar
commons-logging-1.1.1.jar
el-api.jar
geronimo-jpa_3.0_spec-1.1.1.jar
geronimo-jta_1.1_spec-1.1.1.jar
google-api-client-1.18.0-rc.jar
google-api-client-appengine-1.18.0-rc.jar
google-api-client-servlet-1.18.0-rc.jar
google-api-services-datastore-protobuf-v1beta2-rev1-2.1.0.jar
google-http-client-1.18.0-rc.jar
google-http-client-appengine-1.18.0-rc.jar
google-http-client-jackson-1.18.0-rc.jar
google-http-client-jackson2-1.18.0-rc.jar
google-http-client-protobuf-1.18.0-rc.jar
google-oauth-client-1.18.0-rc.jar
google-oauth-client-appengine-1.18.0-rc.jar
google-oauth-client-java6-1.18.0-rc.jar
google-oauth-client-jetty-1.18.0-rc.jar
google-oauth-client-servlet-1.18.0-rc.jar
gson-2.1.jar
guava-17.0.jar
httpclient-4.0.1.jar
httpcore-4.0.1.jar
jackson-core-2.1.3.jar
jackson-core-asl-1.9.11.jar
jcommander-1.32.jar
jdo2-api-2.3-eb.jar
jsp-api.jar
jsr305-2.0.1.jar
protobuf-java-2.5.0.jar
servlet-api.jar
transaction-api-1.1.jar
xpp3-1.1.4c.jar
xstream-1.4.7.jar

I am not sure what I am missing to resolve this issue. Any help would be appreciated, thanks.


回答1:


Ok after some time, I found all the jars I needed. As of this time, https://code.google.com/p/google-api-java-client/wiki/Setup#Download_Library_with_Dependencies is not updated with the full list of jars needed to run the code above. I have the following jars to get it along with my project to work (note: you might not need all of them, but it is a starting place if you are stuck):

appengine-api-labs.jar
appengine-api-stubs.jar
appengine-api.jar
appengine-gcs-client-0.3.9.jar
appengine-local-runtime-shared.jar
commons-lang3-3.2.jar
commons-logging-1.1.1.jar
el-api.jar  
geronimo-jpa_3.0_spec-1.1.1.jar 
geronimo-jta_1.1_spec-1.1.1.jar 
google-api-client-1.18.0-rc.jar 
google-api-client-appengine-1.18.0-rc.jar
google-api-client-servlet-1.18.0-rc.jar 
google-api-services-datastore-protobuf-v1beta2-rev1-2.1.0.jar
google-api-services-storage-v1-rev2-1.18.0-rc.jar
google-http-client-1.18.0-rc.jar
google-http-client-appengine-1.18.0-rc.jar
google-http-client-jackson-1.18.0-rc.jar
google-http-client-jackson2-1.18.0-rc.jar
google-http-client-protobuf-1.18.0-rc.jar
google-oauth-client-1.18.0-rc.jar
google-oauth-client-appengine-1.18.0-rc.jar
google-oauth-client-java6-1.18.0-rc.jar
google-oauth-client-jetty-1.18.0-rc.jar
google-oauth-client-servlet-1.18.0-rc.jar
gson-2.1.jar
guava-17.0.jar
httpclient-4.0.1.jar
httpcore-4.0.1.jar
jackson-core-2.1.3.jar
jackson-core-asl-1.9.11.jar
jcommander-1.32.jar
jdo2-api-2.3-eb.jar
joda-time-2.3.jar
jsp-api.jar
jsr305-2.0.1.jar
protobuf-java-2.5.0.jar
servlet-api.jar
transaction-api-1.1.jar
xpp3-1.1.4c.jar
xstream-1.4.7.jar 

If you want a shorter list to start with, I think in addition to https://code.google.com/p/google-api-java-client/wiki/Setup#Download_Library_with_Dependencies I had to add

google-api-services-storage-v1-rev2-1.18.0-rc.jar
joda-time-2.3.jar


来源:https://stackoverflow.com/questions/24965261/noclassdeffounderror-com-google-api-client-extensions-appengine-http-urlfetchtr

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