[英]How to load StringTemplateGroups from the WEB-INF directory of a web archive
this question is somewhat related to this question: StackOverflow: Howto load a resource from WEB-INF directory of a web archive 这个问题与这个问题有些相关: StackOverflow:如何从Web档案的WEB-INF目录加载资源
I want to use StringTemplate and want to load my templates via a StringTemplateGroup. 我想使用StringTemplate并希望通过StringTemplateGroup加载我的模板。 Until know I use the method shown in the related question to get single files from the WEB-INF folder, but as I read here , it is considered bad practice to load the templates via a path as the application could be inside a WAR file AND I can not use the StringTemplateGroup because of the path.
直到知道我使用相关问题中显示的方法从WEB-INF文件夹中获取单个文件,但正如我在此处所读 ,通过路径加载模板被认为是不好的做法,因为应用程序可能在WAR文件中并且由于路径,我无法使用StringTemplateGroup。
Is there a way to achieve this that you would recommend? 有没有办法实现这一点,你会推荐? Can I get the entire folder as a stream-like object for the StringTemplateGroup to read or is there a decent (and not so hackish) way already implemented in StringTemplate?
我可以将整个文件夹作为StringTemplateGroup读取的类似流的对象,还是已经在StringTemplate中实现了一种不错的(而不是那么hackish)方式?
I am somewhat new to Java but willing to learn :) Thank you very much in advance. 我对Java很新,但愿意学习:)非常感谢你提前。
您可以将context paht的属性添加到JVM运行时参数中,例如,在Tomcat容器中,将参数-DcontextPath = [somewhere]添加到startup.sh文件中,然后通过System.getProperty获取上下文的路径(“contextPath” “)。上下文路径也可以从Tomcat中的-Dcatalina.base获取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.