[Velocity]Unable to find resource .vm file?

Discussion in 'Java' started by Sam Hwang, Apr 19, 2005.

  1. Sam Hwang

    Sam Hwang Guest

    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
     
    Sam Hwang, Apr 19, 2005
    #1
    1. Advertising

  2. Sam Hwang

    . Guest

    On Mon, 18 Apr 2005, Sam Hwang wrote:

    > 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!


    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
     
    ., Apr 20, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darek
    Replies:
    3
    Views:
    2,259
    David Robbins
    Dec 15, 2003
  2. Papa Schultz

    [FR] velocity anakia, xml db, xpath

    Papa Schultz, Feb 12, 2004, in forum: Java
    Replies:
    0
    Views:
    464
    Papa Schultz
    Feb 12, 2004
  3. janib
    Replies:
    0
    Views:
    327
    janib
    Dec 5, 2006
  4. HemantS
    Replies:
    0
    Views:
    802
    HemantS
    Jun 12, 2007
  5. bond
    Replies:
    1
    Views:
    3,277
    Mark Jeffcoat
    Jun 28, 2007
Loading...

Share This Page