Solved

velocity template

Posted on 2007-03-21
3
682 Views
Last Modified: 2010-05-18
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
Comment
Question by:dalecon
3 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 25 total points
ID: 18764425
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
 
LVL 24

Assisted Solution

by:Tomas Helgi Johannsson
Tomas Helgi Johannsson earned 25 total points
ID: 18764515
   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
 

Author Comment

by:dalecon
ID: 18765281
thanks for your replies
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now