2016-04-08 37 views
1

我正在关注http://www.javaworld.com/article/2075966/core-java/start-up-the-velocity-template-engine.html教程。Apache速度:org.apache.velocity.exception.ResourceNotFoundException

我已将我的vm文件保存在与我的课程相同的文件夹中。我得到以下异常:

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

由于velocity文件说,我需要JSP/servlet支持,我不会有现在。

我哪里错了?

PS:我使用IntelliJ IDE

+0

确保模板是在工作目录这可能是根你的模块在IntelliJ中。通过单击“运行”菜单中的“编辑配置”,仔细检查运行时配置。 –

回答

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");