如何设置 Velocity 在 Windows 上的文件系统中查找模板?
我有一个非常简单的 Velocity 应用程序,可以在 Linux 和 MacOS 上运行,但在 Windows 上失败。问题在于资源位置。我只是给它“/”以允许它识别文件系统路径,但在 Windows 上无法识别“c:/.....”路径名。我怀疑有一个更简单的解决方案,但是什么呢?
velocityEngine = new VelocityEngine();
// we want to use absolute paths.
velocityEngine.setProperty("file.resource.loader.path", "/");
try {
velocityEngine.init();
} catch (Exception e) {
throw new MojoExecutionException("Unable to initialize velocity", e);
}
I have a very simple Velocity application that works on Linux and MacOS and fails on Windows. The problem is with the resource locations. I just give it "/" to allow it to recognize file system paths, but on Windows that fails to work for "c:/....." pathnames. I suspect that there is a simpler solution to this, but what?
velocityEngine = new VelocityEngine();
// we want to use absolute paths.
velocityEngine.setProperty("file.resource.loader.path", "/");
try {
velocityEngine.init();
} catch (Exception e) {
throw new MojoExecutionException("Unable to initialize velocity", e);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我将速度模板放入类路径中,并使用 Class.getResourceAsStream 读取它们。
它应该是这样的:
现在 writer 应该保存将参数应用到模板的结果。
威尔·格拉斯(Will Glass)下面的评论看起来值得一看。当我使用速度时,它是生成通知电子邮件,通知电子邮件并不多,而且我将工作外包给一个单独的线程,因此当时性能并不是什么大问题。
I put velocity templates in the classpath and read them in with Class.getResourceAsStream.
It should go something like this:
and now writer should hold the result of applying the parameters to the template.
Will Glass' comment below looks like a good thing to check out. When I was using velocity it was to generate notification emails, there were not a lot of them and I had the work farmed out to a separate thread so performance was not a big deal at the time.