George V. Reilly

NVelocity templates and absolute paths

NVelocity

We’ve started using the NVelocity template formatting engine. We were absolutely stymied for an hour, trying to figure out how to get it working with an absolute path to the template file, instead of the relative path shown in the doc­u­men­ta­tion.

The trick is to set file.resource.loader.path. Here’s how to load C:\foo\bar\­some­file.vm:

ExtendedProperties props = new ExtendedProperties();
props.AddProperty("file.resource.loader.path", new ArrayList(new string[]{".", "C:\\"}));
velocity.Init(props);

template = velocity.GetTemplate("foo\\bar\\somefile.vm");
blog comments powered by Disqus
Review: A Meeting at Corvallis » « NVelocity: loading templates from embedded resources