【问题标题】:How to fix "java.lang.NoClassDefFoundError: com/google/api/client/http/HttpRequestInitializer" runtime error?如何修复“java.lang.NoClassDefFoundError:com/google/api/client/http/HttpRequestInitializer”运行时错误?
【发布时间】:2017-09-14 13:28:33
【问题描述】:

我才刚刚开始学习,如何将 java 与 Goole App Engine Standard 一起使用。 为此,我使用 Eclipse 4.6.3。 我创建了 Web 项目并编写了一些垃圾代码,然后我决定尝试在 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 控制台中看到错误:

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

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

我还在这里添加了这个罐子:

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

(这不是我的屏幕)。

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

【问题讨论】:

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


    【解决方案1】:

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

    1. 使用Google Cloud Tools for Eclipse。使用Properties > Configure > Convert to App Engine Standard Project,然后Properties > Java Build Path > Libraries 并选择Add Library... > Google API Libraries 并选择 Google 云存储
    2. 将您的项目转换为 Maven 或 Gradle,然后add the documented dependencies

    【讨论】:

    • 谢谢。我帮助了Properties &gt; Java Build Path &gt; Libraries and select Add Library… &gt; Google API Libraries and select Google Cloud Storage这一步。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 2021-06-18
    • 2021-10-12
    • 2015-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多