简体   繁体   English

如何在Google App Engine中使用StringTemplate文件?

[英]How do I use StringTemplate files in Google App Engine?

I'm trying to use StringTemplate in Google App Engine to load a template from a file, but I cannot figure out where to put my template files. 我正在尝试使用Google App Engine中的StringTemplate从文件中加载模板,但无法弄清楚将模板文件放在何处。

The documentation says that StringTemplate will "Look for templates in CLASSPATH as resources" but I'm not sure what that means in terms of a GAE deployment. 该文档说StringTemplate将“在CLASSPATH中寻找模板作为资源”,但是我不确定这对GAE部署意味着什么。

For example, suppose I put my templates in a directory called "templates", and put code like this in my servlet: 例如,假设我将模板放在一个名为“模板”的目录中,并将这样的代码放在我的servlet中:

StringTemplateGroup group = new StringTemplateGroup("mygroup", "templates");
StringTemplate st = group.getInstanceOf("homepage");

Then where do I put the "templates" directory? 然后,我应该将“模板”目录放在哪里?

It turns out that it works to put the "templates" directory in your "war" directory. 事实证明,将“模板”目录放入“战争”目录是可行的。

This works locally and deployed to GAE (for me, anyway). 这可以在本地工作并部署到GAE(无论如何对我来说)。

Your "war/WEB-INF/lib" will certainly be on the classpath . 您的“ war / WEB-INF / lib”肯定会在classpath Not sure how appropriate it is to have templates there, though. 不过,不确定在那里有模板是否合适。

Also take a look at this SO question . 也看看这个SO问题

Put them in the root directory of your war/WEB-INF/classes directory and they will wind up in your classpath. 将它们放在war / WEB-INF / classes目录的根目录中,它们就会出现在您的类路径中。 If you're using maven to build you can put them in src/main/resources and they will be copied to your classpath at the root. 如果您正在使用maven进行构建,则可以将它们放在src / main / resources中,它们将被复制到根目录下的类路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM