I have an application packaged inside of a onejar, which uses Velocity for templating.
In my maven project setup, I have a file in $base/src/main/resources/template.html
. When the app gets packaged as a onejar, the resulting onejar contains a nested jar inside of it (under main/my-jar.jar). That jar in turn has that template.html
file packaged under its root. (Apparently maven copied it from src/main/resources into the root of the package)
I'd like to load that template as a resource in Velocity. I've read I need to use a ClassPathResourceLoader to do that, so I have code that looks like this:
VelocityEngine ve = new VelocityEngine();
ve.setApplicationAttribute("resource.loader", "class");
ve.setApplicationAttribute("class.resource.loader.class",
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader.class);
ve.init();
Template t = ve.getTemplate("template.html");
This fails every time, with an exception that none of Velocity's resource loaders can find the file.
I have two questions - first, is this even the right way to configure the use of the ClasspathResourceLoader? And second, if that were configured properly, what path would I specify so that template.html could be found inside of that inner nested jar?