简体   繁体   中英

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

I want to use StringTemplate and want to load my templates via a 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.

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?

I am somewhat new to Java but willing to learn :) Thank you very much in advance.

您可以将context paht的属性添加到JVM运行时参数中,例如,在Tomcat容器中,将参数-DcontextPath = [somewhere]添加到startup.sh文件中,然后通过System.getProperty获取上下文的路径(“contextPath” “)。上下文路径也可以从Tomcat中的-Dcatalina.base获取。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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