velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Elton Hughes <ehug...@novaworks.org>
Subject Resource Not Found Exception
Date Thu, 17 Mar 2005 00:26:07 GMT
Hello All,

First, I am very new to Velocity. I have installed it and I ran 'ant  
test' and it came back successful. I am learning Velocity by reading  
'Pro Jakarta Velocity' by Rob Harrop. In the first example program, I  
entered:

----------
package org.novaworks.ch02;

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

import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

public class HelloWorld {

	public static void main(String[] args) throws Exception {
	
		// initialize Velocity
		Velocity.init();
		
		// get the template
		Template template =  
Velocity.getTemplate("classes/templates/ch02/HelloWorld.vm");
		
		// create a context for Velocity
		VelocityContext context = new VelocityContext();
		
		// create the output
		Writer writer = new StringWriter();
		template.merge(context, writer);
		
		// Write out
		System.out.println(writer.toString());
		
	}
	
}
----------

It compiles, but when I run the program I get:

----------
-> java org.novaworks.ch02.HelloWorld
Exception in thread "main"  
org.apache.velocity.exception.ResourceNotFoundException: Unable to find  
resource 'classes/templates/ch02/HelloWorld.vm'
         at  
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(Re 
sourceManagerImpl.java:458)
         at  
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(Res 
ourceManagerImpl.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.runtime.RuntimeSingleton.getTemplate(RuntimeSingleto 
n.java:285)
         at  
org.apache.velocity.app.Velocity.getTemplate(Velocity.java:469)
         at org.novaworks.ch02.HelloWorld.main(Unknown Source)
->
----------

I know Velocity works because I am able to run the first example  
program that came with the distribution. Any thoughts on what is not  
happening?

Thanks,

Elton
=========================================================
  NOVA                        505 W. Olive Ave. Suite 550
  Elton Hughes (IT)			          Sunnyvale CA 94086
  Phone: 408-730-7235                   Fax: 408-730-7643
---------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message