【发布时间】:2017-06-09 17:53:49
【问题描述】:
这个问题已经被问过了,但我正在尝试接受答案中的相同内容
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
我正在使用velocity生成java代码
我正在设置 maven 项目并且 maven 正在创建 jar
【问题讨论】: