2014-06-21 60 views
5

我正尝试使用Google Cloud Storage Client Library对Appengine进行简单的上载和下载。Google Cloud Storage:无法初始化类OauthRawGcsServiceFactory

执行过程中,它会返回这些错误:

java.lang.NoClassDefFoundError: Could not initialize class com.google.appengine.tools.cloudstorage.oauth.OauthRawGcsServiceFactory 
    at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createRawGcsService(GcsServiceFactory.java:42) 
    at com.google.appengine.tools.cloudstorage.GcsServiceFactory.createGcsService(GcsServiceFactory.java:34) 

错误点到这里:

@Override 
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 
     GcsFilename fileName = getFileName(request); 

     GcsInputChannel readChannel = gcsService.openPrefetchingReadChannel(fileName, 0, BUFFER_SIZE); 
     copy(Channels.newInputStream(readChannel), response.getOutputStream()); 
    } 

    @Override 
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { 
     GcsOutputChannel outputChannel = gcsService.createOrReplace(getFileName(request), GcsFileOptions.getDefaultInstance()); 
     copy(request.getInputStream(), Channels.newOutputStream(outputChannel)); 
    } 

如何解决这个问题?

回答

2

您的/war/WEB-INF/lib/文件夹中缺少一个必需的罐子。

首先,如果您使用Eclipse,请检查“问题”选项卡中是否存在关于资源在服务器上不可用的警告。如果您看到它们,请右键单击QuickFix并选择“复制到...”选项。如果您不使用Eclipse,请手动检查。

如果这没有帮助,请检查您包括所有必要为你的依赖项目:

https://code.google.com/p/google-api-java-client/wiki/Setup#Download_Library_with_Dependencies

+0

我试过你的解决方案,但它没有奏效。谢谢,@Andrei Volgin! – benjtupas

0

始终使用像Maven的或常春藤工具来解决依赖你。将JAR复制到war/WEB-INF/lib/目录并手动编辑.classpath文件将是痛苦的,并且可能无法帮助您始终。如果您使用Eclipse & Google App Engine插件,请使用添加Google API ...如此处所述 - Google Plugin for Eclipse。在我的情况下,通过Google Plugin for Eclipse添加Cloud Storage API有助于解决此问题NoClassDefFoundError

+0

找不到云存储Api每个sey,但添加云存储json api列出在那里做了我的诡计 – jai

1

此问题的可能原因之一是GCS库所需的库不存在。当Google在他们的文档中声明您需要1)Guava,2)Joda-Time,3)云存储API客户端库 - 他们不是在开玩笑。

问题是,您不需要这些库在开发服务器上运行您的应用程序。您的应用程序在本地运行良好。但是,当您将其上传到Google时,您会收到一条NoClassDefFoundError消息:它会报告OAuthRawGcsServiceFactory或URLFetchUtils,即使缺少的类位于Joda或CS API中。

一旦你包括一切 Google要求,您的项目(希望)将工作。下载这些库的链接可以在Appengine Docs页面找到:https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/download

相关问题