Solved

velocity template

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Strange loading of website behaviour 3 32
recursion example 16 112
GUI builder for Eclipse? 8 27
MySQL  on Tomcat 8 30
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

867 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

16 Experts available now in Live!

Get 1:1 Help Now