【问题标题】:Google Cloud Storage: Could not initialize class OauthRawGcsServiceFactory谷歌云存储:无法初始化类 OauthRawGcsServiceFactory
【发布时间】:2014-06-21 07:06:12
【问题描述】:

我正在尝试使用 Google Cloud Storage 客户端库在 Appengine 上进行简单的上传和下载。

在执行期间,它返回这些错误:

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) );
    }

我该如何解决这个问题?

【问题讨论】:

    标签: java google-app-engine google-cloud-storage


    【解决方案1】:

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

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

    如果这没有帮助,请检查您是否包含了项目所需的所有依赖项:

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

    【讨论】:

    • 我尝试了您的解决方案,但没有奏效。谢谢,@Andrei Volgin!
    【解决方案2】:

    导致此问题的一个可能原因是缺少 GCS 库所需的库。当 Google 在他们的文档中声明您需要 1) Guava、2) Joda-Time、3) Cloud Storage API 客户端库时 - 他们不是在开玩笑。

    问题是,您不需要这些库来在开发服务器上运行您的应用程序。您的应用程序将在本地正常工作。但是,当您将其上传到 Google 时,您会收到带有错误消息的 NoClassDefFoundError:它会报告 OAuthRawGcsServiceFactory 或 URLFetchUtils,即使缺少的类在 Joda 或 CS API 中也是如此。

    一旦您包含了 Google 要求的所有内容,您的项目(希望如此)就可以运行。这些库的下载链接可以在 Appengine 文档页面上找到:https://cloud.google.com/appengine/docs/java/googlecloudstorageclient/download。

    【讨论】:

      【解决方案3】:

      始终使用 Maven 或 Ivy 等工具为您解决依赖关系。将 JAR 复制到 war/WEB-INF/lib/ 目录并手动编辑 .classpath 文件会很痛苦,并且可能不会总是对您有所帮助。如果您使用 Eclipse 和 Google App Engine 插件,请使用此处提到的 添加 Google API... - Google Plugin for Eclipse。就我而言,通过 Google Plugin for Eclipse 添加 Cloud Storage API 有助于解决此问题NoClassDefFoundError。

      【讨论】:

      • Couldnt find the Cloud Storage Api per sey 但是添加那里列出的云存储 json api 对我有用
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-13
      • 1970-01-01
      • 2020-09-10
      • 1970-01-01
      • 2016-10-12
      相关资源
      最近更新 更多