java - 如何修复 "java.lang.NoClassDefFoundError: com/google/api/client/http/HttpRequestInitializer"运行时错误?

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

我才刚刚开始学习如何将 java 与 Goole App Engine Standard 结合使用。 我为此使用 Eclipse 4.6.3。 我创建了网络项目并编写了一些垃圾代码,然后我决定尝试在 Google Cloud Storage 中列出文件。 这是我的代码:

public static ArrayList<String> getFilesInBucket(String bucket_name)
{
/*Line 235*/GcsService gcsService = GcsServiceFactory.createGcsService(RetryParams.getDefaultInstance());

    ListResult result = null;
    try { result = gcsService.list(bucket_name, ListOptions.DEFAULT); }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    ArrayList<String> files = new ArrayList<String>();

    while (result.hasNext())
    {
        ListItem l = result.next();

        if (!l.isDirectory())
            files.add(l.getName());
    }

    return files;
}

这个垃圾在本地工作,但是在我部署它之后它就停止了。我在 Google Console 中看到错误:

java.lang.NoClassDefFoundError: com/google/api/client/http/HttpRequestInitializer
at MyJunk.getFilesInBucket (ADServlet.java:235)

添加到 src 中 lib 目录的每个 jar 也会添加到 web-inf/lib 中。 enter image description here

我还在此处添加了这个 jar : enter image description here

我什至打开了“问题”选项卡并快速修复了每个“Eclipse 警告:XXXXXXXXXXX.jar 将不会导出或发布”。垃圾是这样的: enter image description here

(这不是我的屏幕)。

但是我的代码在 GAE 标准上运行时失败...我还能做些什么来解决这个问题?

最佳答案

Google Cloud 库有很多依赖项。与其尝试用手追赶它们,不如让机器为您做这件事。两个建议:

  1. 使用Google Cloud Tools for Eclipse 。使用属性 > 配置 > 转换为 App Engine 标准项目,然后属性 > Java 构建路径 > 库并选择添加库... > Google API 库> 并选择Google Cloud Storage
  2. 将您的项目转换为 Maven 或 Gradle,然后 add the documented dependencies .

关于java - 如何修复 "java.lang.NoClassDefFoundError: com/google/api/client/http/HttpRequestInitializer"运行时错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46220479/

相关文章:

java - 选择单个单词或字符串(双击)以进行编辑

java - 仅当字符未直接包含在所需字符串之前时,正则表达式才匹配

javascript - 在后端代码中添加 JSON 中的额外字段

java - docker环境下spring boot外部配置: application. yml不存在

Eclipse/STS Java 编辑器背景色强制白色

eclipse - 禁用 Eclipse 中的语法高亮

python - 在 Python 中模拟 Google App Engine 文件上传

python - 通过 GAE header 问题发布请求

python - 谷歌appengine应用授权

java - 在运行时重新初始化 spring 中的 bean