[英]Velocity can't find resource with webApp
I'm trying to create a webApp using GlashFish server and Velocity. 我正在尝试使用GlashFish服务器和Velocity创建一个webApp。
But i get the following error: 但是我收到以下错误:
SEVERE: ResourceManager : unable to find resource 'temp.vm' in any resource loader.
SEVERE: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'temp.vm'
velocity.proprieties: velocity.proprieties:
resource.loader=webapp
webapp.resource.loader.class=org.apache.velocity.tools.view.WebappResourceLoader
webapp.resource.loader.path=/WEB-INF/templates/
Servlet: Servlet的:
ve.setApplicationAttribute("javax.servlet.ServletContext", context);
template = ve.getTemplate("temp.vm");
I am using NetBeans IDE and my temp.vm file is in /WEB-INF/templates/. 我正在使用NetBeans IDE,并且我的temp.vm文件位于/ WEB-INF / templates /中。 The must be somethings I'm missing but I just can't get what it is. 一定是我所缺少的东西,但我无法理解它到底是什么。
Thank you for your help! 谢谢您的帮助!
另一个选择是使用类路径资源加载器,然后将.vm文件放入/WEB-INF/classes
。
put the template in /WEB-INF/classes/template/temp.vm directory and use ve.getTemplate("template/temp.vm"); 将模板放在/WEB-INF/classes/template/temp.vm目录中,并使用ve.getTemplate(“ template / temp.vm”);
make sure to configure the resource loader to ClasspathResourceLoader. 确保将资源加载器配置为ClasspathResourceLoader。
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<props>
<prop key="resource.loader">class</prop>
<prop key="class.resource.loader.class">org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader</prop>
</props>
</property>
</bean>
I just asked a similar question: 我只是问了一个类似的问题:
How to load a velocity template into an EJB to be used as a mail template 如何将速度模板加载到EJB中用作邮件模板
I used the ClasspathResourceLoader and created a .jar containing the templates. 我使用ClasspathResourceLoader并创建了一个包含模板的.jar。 Put that .jar into the WEB-INF/lib folder and it should work (at least I could manage getting things up running that way). 将该.jar放到WEB-INF / lib文件夹中,它应该可以工作(至少我可以设法使事情以这种方式运行)。
Hope it helps :) 希望能帮助到你 :)
Regards, Alex 问候,亚历克斯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.