2014-06-21 58 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

相關問題