2016-04-08 84 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");