在多模块Google AppEngine中获取资源文件

时间:2015-05-27 14:27:21

标签: java google-app-engine build.gradle

我正在关注此文档: https://cloud.google.com/appengine/docs/java/config/appconfig#Static_Files_and_Resource_Files 设置特定的资源文件位置,如下所示:

应用服务引擎-web.xml中:

task

现在,我需要在servlet上下文之外获取资源文件。所以,我正在尝试使用以下文件获取文件:

vendorUpdatedItem

这在Local Development Server上运行正常,但在生产时,我收到IOException:

'object' does not contain a definition for 'job' and no extension method 'job' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

这是我的GAE模块结构:

<resource-files>
        <include path="/resources/*" />
</resource-files>

我误读了这份文件吗?资源文件的正确路径应该是什么?

其他细节:

  • 我刚刚从单个模块AppEngine app迁移 - 只使用classLoader.getResourceFromStream足以从src / main / resources获取我的资源,但这对于ear结构不再有效。

  • 我正在使用Gradle进行配置,如appengine示例中所示: https://github.com/GoogleCloudPlatform/appengine-modules-sample-java

  • 我无法使用ServletContext.getResources,因为我无法访问需要这些资源文件的服务中的“servlet上下文”。 (虽然我可以一直传递它,如果它是绝对必要的 - 但基于文档,听起来像java.io.File应该能够得到我的资源文件,如果我正确地知道路径)

  • 如果有人可以在我的“build.gradle”中建议正确的设置,只需将资源放在gradle-appengine-plugin将其拾取并放在GAE prod的当前路径中的位置,这将是一个完美的解决方案!

1 个答案:

答案 0 :(得分:0)

当前目录包含“WEB-INF”和“_ah”文件夹。

以下是结构在WEB-INF中的显示方式:

WEB-INF
 - <all my files from my normal WEB-INF>
 - resources <<< The folder I added under <resource-files>
 - lib
 - classes
 - appengine-generated

我能够通过使用此代码段列出本地文件来解决这个问题:

File curDir = new File("./WEB-INF");
File[] files = curDir.listFiles();
for (File file: files) {
  logger.info(file.getName());
}