速度无法找到资源 [英] Velocity Unable To find Resources

查看:63
本文介绍了速度无法找到资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题已经被问到了,但我正在尝试接受的答案中的相同内容

This question is already asked but i am trying the same thing that is in accepted answer

protected static final String RESOURCE_LOADER = classpath.resource.loader.class";    

static {
    System.out.println("Velocity Initialization Started");
    velocityEngine = new VelocityEngine();
    velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    velocityEngine.setProperty(RESOURCE_LOADER,ClasspathResourceLoader.class.getName());
    try {
        velocityEngine.init();
    } catch (Exception e) {

        LOG.error("Failed to load velocity templates e={}", e); 
    }
}

我的速度文件位于

src/main/resources/velocity/templates/command/name.vm

我正在通过以下命令获取模板

i am getting templates by following command

template = velocityEngine.getTemplate("velocity/templates/command/GenericState.vm");

它在本地可用,但是当捆绑在jar中时不起作用,我已经检查了它包含Velocity文件夹的

It works locally but when bundled in jar it does not work , I have examined the jar it consist of velocity folder

我正在使用速度生成Java代码

i am using velocity to generated java code

我正在执行Maven项目设置,而Maven正在创建jar

I am having maven project setup and maven is creating jar

推荐答案

尝试以这种方式工作.

velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "class,file");
    velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.Log4JLogChute");
    velocityEngine.setProperty("runtime.log.logsystem.log4j.logger", "VELLOGGER");
    velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
    velocityEngine.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogSystem");
    velocityEngine.init();

这篇关于速度无法找到资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆