Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Velocity Resource File Not Found Exception

843785Aug 7 2008 — edited Aug 7 2008
hi there,

im new hand to using the Velocity tech, when i tried to use it i got the following exception (resource file not found!)

(Successful case)
when i put the template file in F:\eclipse\workspace\Testing\src\VMDemo.vm, velocity can found it successful.
(Fail case)
when i put the template file in C:\template\VMDemo.vm, velocity can't found it.

Java file saved at F:\eclipse\workspace\Testing\src\com\testing\vm\VMDemo.java

is it i need to change the config of velocity?

package com.testing.vm;

import java.io.StringWriter;
import java.io.Writer;

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.tools.generic.RenderTool;

public class VMDemo {

  public static void main(String[] args) throws Exception {
    Velocity.init();
    Template t = Velocity.getTemplate(".\\src\\VMDemo.vm"); // correct output end success to found the vm file
    Template t = Velocity.getTemplate("C:\\template\\VMDemo.vm"); // throw resource file not found exception

    VelocityContext ctx = new VelocityContext();

    Writer writer = new StringWriter();
    t.merge(ctx, writer);

    System.out.println(writer);
  }
}
VMDemo.vm
=========================================
#set ($companyName = "Name")
<html>
<head>
<title>$companyName Homepage</title>
</head>
<body>
<h1>Welcome!!</h1>
#if ($userType == "VIP")
<h2>You are a VIP!</h2>
#else
<h2>You are not a VIP!</h2>
#end
</body>
</html>

Many thank

Edited by: EricWong on Aug 7, 2008 8:29 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 4 2008
Added on Aug 7 2008
3 comments
477 views