Velocity can't find resource with webApp
I'm trying to create a webApp using GlashFish server and Velocity.
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:
resource.loader=webapp
webapp.resource.loader.class=org.apache.velocity.tools.view.WebappResourceLoader
webapp.resource.loader.path=/WEB-INF/templates/
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/. The must be somethings I'm missing but I just can't get what it is.
Thank you for your help!
Another option might be to use the class path resource loader and put your .vm files in /WEB-INF/classes
.
I just asked a similar question:
How to load a velocity template into an EJB to be used as a mail template
I used the ClasspathResourceLoader and created a .jar containing the templates. Put that .jar into the WEB-INF/lib folder and it should work (at least I could manage getting things up running that way).
Hope it helps :)
Regards, Alex
put the template in /WEB-INF/classes/template/temp.vm directory and use ve.getTemplate("template/temp.vm");
make sure to configure the resource loader to 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>
精彩评论