我才刚刚开始学习如何将 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 中。
我什至打开了“问题”选项卡并快速修复了每个“Eclipse 警告:XXXXXXXXXXX.jar 将不会导出或发布”。垃圾是这样的:
(这不是我的屏幕)。
但是我的代码在 GAE 标准上运行时失败...我还能做些什么来解决这个问题?
最佳答案
Google Cloud 库有很多依赖项。与其尝试用手追赶它们,不如让机器为您做这件事。两个建议:
- 使用Google Cloud Tools for Eclipse 。使用属性 > 配置 > 转换为 App Engine 标准项目,然后属性 > Java 构建路径 > 库并选择添加库... > Google API 库> 并选择Google Cloud Storage。
- 将您的项目转换为 Maven 或 Gradle,然后 add the documented dependencies .
关于java - 如何修复 "java.lang.NoClassDefFoundError: com/google/api/client/http/HttpRequestInitializer"运行时错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46220479/