简体   繁体   English

如何从Web存档的WEB-INF目录加载StringTemplateGroups

[英]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.

相关问题 如何从Web存档的WEB-INF目录加载资源 - How to load a resource from WEB-INF directory of a web archive 如何从WEB-INF目录加载文件/属性? - How to load files/properties from WEB-INF directory? zk框架:如何从WEB-INF的目录zul下加载zul页面 - zk framework: how to load zul pages from WEB-INF under directory zul Java,Tomcat-运行时可以从WEB-INF / lib目录中加载资源吗? - Java, Tomcat - Can you load a resource during run-time from the WEB-INF/lib directory? 将文件从WEB-INF / wsdl / Schemas / Messages /目录加载到jboss eap 6.4中的类路径 - Load files from WEB-INF/wsdl/Schemas/Messages/ directory to class path in jboss eap 6.4 如何从WEB-INF / classes目录中的类写入WebContent目录中的文件 - How to write to a file in WebContent directory from a class in WEB-INF/classes directory 可以从WEB-INF \\ lib \\ {*。jar} \\ META-INF \\ resources \\ WEB-INF目录访问tld文件吗? - Can tld files be accessed from WEB-INF\lib\{*.jar}\META-INF\resources\WEB-INF directory? 无法在归档文件“ xxxx”中加载资源“ WEB-INF / ibm-web-bnd.xml” - Could not load resource “WEB-INF/ibm-web-bnd.xml” in archive “xxxx” 使用Spring从WEB-INF文件夹加载文件 - Load file from WEB-INF folder using Spring 从web-inf \\ lib \\ *。jar中的代码文件加载 - Load from code file from web-inf\lib\*.jar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM