• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 692
  • Last Modified:

velocity template

hi all

i'm trying to load a velocity template that is on my c: drive but i keep getting an error that the resource cannot be found.  it can'tfind the vm template on my c drive

VelocityEngine engine = new VelocityEngine();
engine.init();
Template t = engine.getTemplate("notes.vm"); - i've also tried Template t = engine.getTemplate("c:\\notes.vm");
VelocityContext context = new VelocityContext();
context.put("blaa", "blaa");
Writer writer = new StringWriter();            
t.merge(context, writer);      
velocitytemplate = writer.toString();

thanks for any help
0
dalecon
Asked:
dalecon
2 Solutions
 
TimYatesCommented:
From: https://issues.apache.org/jira/browse/VELOCITY-446?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

---------------
Using a resource loader makes sure that you cannot load arbitrary files from the file system. Inside Velocity there is no concept of files, only of templates.

I understand that this might be a convenience method at best. You would be far better off by writing a ResourceManager implementation that does exactly this for you, then plug it in using the "resource.manager.class" and just use getTemplate("path to file").

It is all in there in Velocity. :-)
---------------

And if you look here: http://today.java.net/pub/a/today/2003/12/16/velocity.html?page=last

It shows you how to use ResourceLoaders (ClasspathResourceLoader to be exact)

Hope that helps

Tim
0
 
Tomas Helgi JohannssonCommented:
   Hi!

Try engine.getTemplate("./notes.wm") or engine.getTemplate("file://c/notes.vm")
Here is an example to look at : http://www.java2s.com/Code/Java/Velocity/ResourceLoaderDemo.htm

Regards,
  Tomas Helgi
0
 
daleconAuthor Commented:
thanks for your replies
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now