Java 在多模块Google AppEngine中获取资源文件
我正在关注这个文件: 要设置特定的资源文件位置,请执行以下操作: appengine-web.xml:Java 在多模块Google AppEngine中获取资源文件,java,google-app-engine,build.gradle,Java,Google App Engine,Build.gradle,我正在关注这个文件: 要设置特定的资源文件位置,请执行以下操作: appengine-web.xml: <resource-files> <include path="/resources/*" /> </resource-files> 这在本地开发服务器上运行良好,但在生产环境中,我遇到了一个IOException: getResourceAsString: /base/data/home/apps/s~my-app-id/module2:
<resource-files>
<include path="/resources/*" />
</resource-files>
这在本地开发服务器上运行良好,但在生产环境中,我遇到了一个IOException:
getResourceAsString: /base/data/home/apps/s~my-app-id/module2:multi-module-1.384597049666152751/default/WEB-INF/resources/query_url.json (No such file or directory)
以下是我的GAE模块结构:
root-ear
- default
- src/main/webapp/WEB-INF
- resources
- src/main/java (some code)
- module2
- src/main/java (code that needs the resource)
我看错文件了吗?资源文件的正确路径应该是什么
其他详情:
我刚从一个单一模块AppEngine应用程序迁移过来——在那里,仅使用classLoader.getResourceFromStream就足以从src/main/resources获取我的资源,但这在ear结构中不再起作用
我将Gradle用于appengine示例中建议的配置:
我无法使用ServletContext.getResources,因为我无法访问需要这些资源文件的服务中的servlet上下文。虽然如果绝对需要的话,我可以一路把它传进来——但是根据文档,如果我正确地知道路径,java.io.File应该可以把资源文件传给我
如果有人能在my build.gradle中建议正确的设置,将资源放在gradle appengine插件将拾取并将其放在GAE prod的当前路径上的位置,那将是一个完美的解决方案
当前目录包含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
此外,resources文件夹的位置和设置也很重要—它必须是访问资源的同一模块。默认模块中的资源文件对module2模块不可见
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());
}