You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by James You <jy...@hywy.com> on 2001/10/07 00:16:09 UTC

How to set valocity property

Hi, all:
I am new to Velocity Tempalte Engine. The follwing code is used to
create a Velocity context.
		
                // first, we init the runtime engine.
                Properties prop = new Properties();

                String templatePropertyFile =
this.getTemplateFileRoot_() + "velocity.properties";
            
                File tempProperty = new File(templatePropertyFile);
                FileInputStream fiStr = new
FileInputStream(tempProperty);
                prop.load(fiStr);
                
            
                prop.setProperty("velocimacro.library",
"template/VelocityMacro.vm");


                Velocity.init( prop );

                Log_.info(THIS + " Template source path --> " +
Velocity.getProperty("resource.loader.1.resource.path"));

                // then we init the define properties for runtime
engine.
                Velocity.init();

                // let's make a Context and put data into it */
                vContext = new VelocityContext();
 

I am using JBuilder to develop the project
	the project's current working directory is in sub directory of
"classes" under the my project's home
		$MyProject_Home\classes
In fact, my tempalte file (called myTemplate.vm) is located in 
		$MyProject_Home\classes\template\myTemplate.vm

In the property file (velocity.properties), I set the the tempalte
file's root directory

		resource.loader.1.resource.path = .\\template\\

The problem I had is that 
		Velocity always looking for myTemplat.vm find in the current
directory, i.e.
		under the directory $MyProject_Home\classes\		
		I had to put myTemplate.vm file under the "classes' the directory
		i.e:  $MyProject_Home\classes\myTemplate.vm

If I put myTemplate.vm into
$MyProject_Home\classes\template\myTemplate.vm, it will never
find it no matter how I change the property
(resource.loader.1.resource.path) value formats in the
velocity.properties file.
		resource.loader.1.resource.path = template
		resource.loader.1.resource.path = /template/
		resource.loader.1.resource.path = /template
		resource.loader.1.resource.path = //template
		resource.loader.1.resource.path = \\template\\
		....
		
Does the format of proerty setting for resource.loader.1.resource.path
(resource.loader.1.resource.path = .\\template\\)
is wrong???

Can any one help me to solve this property? i.e. how to define 
valocity's property (resource.loader.1.resource.path...etc.)
so as to let velocity to load those tempalte file (*.vm) under the
sepcific location instead of in the current working directory?


Thanks you in advanced!



JamesLong

Re: How to set valocity property

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 10/6/01 6:16 PM, "James You" <jy...@hywy.com> wrote:

> Hi, all:
> I am new to Velocity Tempalte Engine. The follwing code is used to
> create a Velocity context.

[SNIP]

> 
> Can any one help me to solve this property? i.e. how to define
> valocity's property (resource.loader.1.resource.path...etc.)
> so as to let velocity to load those tempalte file (*.vm) under the
> sepcific location instead of in the current working directory?
>

First, read the documentation on configuring resource loaders in the
developers guide.

Second - where are you getting the

Resource.loader.1.path

format?  We haven't used that since pre-1.0 release?  Where are you finding
it?

Have you considered giving it an absolute path?  Like

file.resource.loader.path = C:\foobar\templates


Let us know.

Geir

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin