You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Michael Oliver <ol...@alariussystems.com> on 2005/10/03 17:58:18 UTC
resource not found
I was breezing along, generating Hibernate config files from velocity
templates and all was well.
I had my velocity templates located in the classpath of the web app that was
doing the work at
/classes/com/alarius/datasource/Hibernate_cfg_xml.vm and I packaged the
working tested version up into a jar and deployed that into another web app
that would be doing that same thing.
VelocityEngine ve = new VelocityEngine();
ve.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, this);
ve.setProperty(Velocity.RESOURCE_LOADER, "class");
ve.setProperty("class.resource.loader.class","org.apache.velocity.runtime.re
source.loader.ClasspathResourceLoader");
VelocityContext context = new VelocityContext();
.context values set..n/a
StringWriter sw = new StringWriter();
try {
ve.init();
//remember to omit the leading slash as it will be looking in the
classpath
ve.mergeTemplate("com/alarius/datasource/Hibernate_cfg_xml.vm",
Velocity.ENCODING_DEFAULT,context, sw);
} catch (ResourceNotFoundException e) {
e.printStackTrace();
}
Running the above yields:
org.apache.velocity.exception.ResourceNotFoundException: Unable to find
resource 'com/alarius/datasource/Hibernate_cfg_xml.vm'
at
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(Resour
ceManagerImpl.java:501)
at
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(Resourc
eManagerImpl.java:384)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java
:814)
at
org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:482
)
Not only did I try it with the jar file with the velocity templates in the
path starting at com/alarius, but I put the templates in the webapp
WEB-INF/classes/com/alarius/datasource/ directory as well.
The Classpath loader is defined and set in the velocity engine properties.
Any clues will be appreciated.
Ollie