Solved

velocity template

Posted on 2007-03-21
3
686 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 25

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb on wildfly 5 48
going to wrong jsp page 2 50
What browser will run Java? 7 127
How to retrieve the HTTPServletResponse header field in script tag 1 28
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

726 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