import java.io.StringWriter;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.*;
public class Velomayor {
public static void main(String args[]) {
try{
VelocityEngine engine = new VelocityEngine();
engine.init();
Template t = engine.getTemplate("hello.vm");
VelocityContext context = new VelocityContext();
context.put("name", "world");
StringWriter writer = new StringWriter();
t.merge(context, writer);
System.out.println(writer.toString());
}
catch(Exception e){
e.printStackTrace();
System.exit(0);
}
}
}
org.apache.velocity.exception.ResourceNotFoundException: Unable to find
resource 'C:\hello.vm'
at
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:458)
at
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:341)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:831)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:813)
at
org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:470)
at common.Velomayor.main(Velomayor.java:26)
The template file hello.vm just resides inside the same folder as the
.java file.
Any idea? Thanks!
Regards,
Sam Hwang
Check the docs for org.apache.velocity.app.VelocityEngine.getTemplate();
Is the input a path to the file? Can you do:
engine.getTemplate("./hello.vm");
Or do you have to set the current directory and use the code as it? That
is:
// code to change the current directory for getTemplate goes here
engine.getTemplate("hello.vm");
Or course, if you just want to see it work, copy the hello.vm to C:\ and
you are good to go.
--
Send e-mail to: darrell dot grainger at utoronto dot ca