Solved

velocity template

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle 11g 23 84
eclipse apache tomcat admin console 52 97
type mismatch (Object[] to double[] 4 24
jboss wildfly 10.1 10 99
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

821 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