Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Velocity]Unable to find resource .vm file?

503 views
Skip to first unread message

Sam Hwang

unread,
Apr 18, 2005, 10:43:52 PM4/18/05
to
Hello,
I follow to code the tutorial from JavaWorld but received the following
error:

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

.

unread,
Apr 20, 2005, 10:13:15 AM4/20/05
to

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

0 new messages