You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ian Stevens <ia...@phantomfiber.com> on 2004/04/26 21:43:40 UTC
Problems programmatically setting the file resource loader path
The following code, created for testing purposes, does not work for me:
// Write a temporary template.
File file = File.createTempFile( "template", ".vm" );
FileWriter out = new FileWriter( file );
out.write( "${name}" );
out.close();
// Init the engine
VelocityEngine ve = new VelocityEngine();
ve.init();
ve.setProperty( Velocity.FILE_RESOURCE_LOADER_PATH, file.getParent()
);
// Load the template - this fails with a
org.apache.velocity.exception.ResourceNotFoundException
Template template = ve.getTemplate( file.getName() );
When I step through the code and examine the VelocityEngine after the
property is set, the setting exists in VeloctyEngine.overridingProperties,
but is "." in VelocityEngine.configuration. The error generated on that
last call is "org.apache.velocity.exception.ResourceNotFoundException:
Unable to find resource 'template9545.vm'".
What is a correct way to programmatically set the file resource loader path
so that the above code will work?
(This is on a Windows machine, BTW. I have not yet tried this on a Unix
machine.)
thanks,
ian.
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
RE: Problems programmatically setting the file resource loader path
Posted by Ian Stevens <ia...@phantomfiber.com>.
> Set first, then init() :
Thanks. Works like a charm.
ian.
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: Problems programmatically setting the file resource loader path
Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Apr 26, 2004, at 3:43 PM, Ian Stevens wrote:
> The following code, created for testing purposes, does not work for me:
>
> // Write a temporary template.
> File file = File.createTempFile( "template", ".vm" );
> FileWriter out = new FileWriter( file );
> out.write( "${name}" );
> out.close();
>
> // Init the engine
> VelocityEngine ve = new VelocityEngine();
> ve.init();
> ve.setProperty( Velocity.FILE_RESOURCE_LOADER_PATH, file.getParent()
> );
Set first, then init() :
ve.setProperty()
ve.init()
--
Geir Magnusson Jr 203-247-1713(m)
geir@4quarters.com
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org