速度无法找到资源

Velocity Unable To find Resources

这个问题已经有人问过,但我正在尝试接受答案中的相同问题

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

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

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

它在本地工作,但当捆绑在 jar 中时它不起作用,我检查了它包含 velocity 文件夹的 jar

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

我正在设置 maven 项目并且 maven 正在创建 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();