Hi Guys,
please help, I am trying to create a basic program that runs a template
called resource.vm. Now both my class and my resource.vm file is in the src
folder but I get this exception within the eclipse IDE:
SEVERE: ResourceManager : unable to find resource 'resource.vm' in any
resource loader.
org.apache.velocity.exception.ResourceNotFoundException: Unable to find
resource 'resource.vm'
at
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
at
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1077)
at
org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:528)
at test.velocity.VelocityTestClass.main(VelocityTestClass.java:27)
My code is as follows:
try {
/*Add and initialize an engine*/
VelocityEngine ve = new VelocityEngine();
ve.init();
boolean isExists = ve.resourceExists("resource.vm");
System.out.println(isExists);
/*Get the template*/
Template te = ve.getTemplate("resource.vm");
/*Create a context to add data*/
VelocityContext vc = new VelocityContext();
vc.put("name", "Adnan");
/*Now render the template in a string writer*/
StringWriter sw = new StringWriter();
te.merge(vc, sw);
System.out.println(sw.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Any help would be appreciated.
Thanks!
--
View this message in context:
http://old.nabble.com/Resource-Loader-Issues-tp32196942p32196942.html
Sent from the Velocity - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]