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);
}
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.