Apache velocity:org.apache.velocity.exception.ResourceNotFoundException

时间:2016-04-08 14:20:20

标签: java apache velocity

我正在关注http://www.javaworld.com/article/2075966/core-java/start-up-the-velocity-template-engine.html教程。

我已将vm文件保存在与我班级相同的文件夹中。我得到以下例外:

Exception in thread "main" org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource

正如velocity文档所说,我需要JSP/servlet支持,而我现在还没有。{/ p>

我哪里错了?

PS:我正在使用IntelliJ IDE

1 个答案:

答案 0 :(得分:0)

尝试在Velocity引擎中设置RuntimeConstants.RESOURCE_LOADERclasspath.resource.loader.class以查看源代码:

VelocityEngine engine = new VelocityEngine();
engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName())

//this is at src/main/java level, tested with Netbeans
Template yourTemplate = ve.getTemplate("yourTemplate.vm"); 
相关问题