简体   繁体   English

Velocity模板-线程“ main”中的异常org.apache.velocity.exception.ResourceNotFoundException:无法找到资源

[英]Velocity Template - Exception in thread “main” org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource

I have tried running simple velocity template program in java eclipse and getting below error: 我试过在Java Eclipse中运行简单的速度模板程序,并遇到以下错误:

Sep 22, 2017 4:53:14 PM org.apache.velocity.runtime.log.CommonsLogLogChute log
SEVERE: ResourceManager : unable to find resource 'templates/HelloWorld.vm' in any resource loader.
Exception in thread "main" org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'templates/HelloWorld.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 com.sapient.velocity.HelloVelocity.main(HelloVelocity.java:18)

tried everything checking errors online stackoverflow: 尝试了一切在线检查错误stackoverflow:

my project structure: 我的项目结构:

在此处输入图片说明

HelloWorld.vm : HelloWorld.vm

Velocity Template $helloWorld

HelloVelocity Class

public class HelloVelocity {

    public static void main(String[] args) {
        VelocityEngine ve = new VelocityEngine();
        ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
        ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
        ve.init();
        Template t = ve.getTemplate("templates/HelloWorld.vm");
        VelocityContext vc = new VelocityContext();
        vc.put("helloWorld", "Hello World!!!");
        StringWriter sw = new StringWriter();
        t.merge(vc, sw);
        System.out.println(sw);
    }
}

I am using Velocity 1.7 build. 我正在使用Velocity 1.7构建。

Rename the file HelloWorld.vm in your resource folder instead of HelloWold.vm . 重命名资源文件夹中的文件HelloWorld.vm而不是HelloWold.vm There is a mismatch in the filename. 文件名不匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.apache.velocity.exception.ResourceNotFoundException:无法找到资源“模板/电子邮件/test.vm” - org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'templates/email/test.vm' org.apache.velocity.exception.ResourceNotFoundException - org.apache.velocity.exception.ResourceNotFoundException Apache velocity:org.apache.velocity.exception.ResourceNotFoundException - Apache velocity: org.apache.velocity.exception.ResourceNotFoundException 如何在模式生成期间修复“org.apache.velocity.exception.ResourceNotFoundException” - How to fix “org.apache.velocity.exception.ResourceNotFoundException” during schema generating 线程“主”中的异常org.apache.velocity.exception.VelocityException - Exception in thread “main” org.apache.velocity.exception.VelocityException 速度模板资源未找到异常 - velocity template resource not found exception Apache Android 中的速度(“无法找到资源”) - Apache Velocity in Android("unable to find resource") Velocity 2.0无法在jar中找到模板资源 - Velocity 2.0 unable to find template resource in jar 错误[org.apache.velocity] ResourceManager:无法在任何资源加载器中找到资源“ layout.vm” - ERROR [org.apache.velocity] ResourceManager : unable to find resource 'layout.vm' in any resource loader 错误org.apache.velocity:ResourceManager:无法在任何资源加载器中找到资源'xxx.html.vm' - ERROR org.apache.velocity : ResourceManager : unable to find resource 'xxx.html.vm' in any resource loader
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM