Java Velocity 相关问题

错误原因:

Exception in thread "main" org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource '/hellotest.vm'
at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474)
at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1514)
at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:373)
at InitVelocity.main(InitVelocity.java:30)

解决方法:

    使用含有 properties 的 VelocityEngine 的实现方法。

Properties properties = new Properties(); 
properties.setProperty("resource.loader","class");
properties.setProperty("class.resource.loader.class","org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
properties.setProperty(Velocity.INPUT_ENCODING,"UTF-8");
properties.setProperty(Velocity.OUTPUT_ENCODING,"UTF-8");
VelocityEngine ve = new VelocityEngine(properties);

你可能感兴趣的:(TO,velocity,find,resource,Unable)