gpt4 book ai didi

apache - Velocity 找不到资源

转载 作者:行者123 更新时间:2023-12-02 02:54:37 25 4
gpt4 key购买 nike

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

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 中时它不起作用,我已经检查了它由速度文件夹组成的 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();

关于apache - Velocity 找不到资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44451069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com