velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "carlo latasa" <clat...@gmail.com>
Subject Re: VelocityEngine...
Date Fri, 05 Dec 2008 00:39:08 GMT
So now I've followed your recommendations about using the latest tools jar
as well as replacing the file resource loader with the webapp one in my
velocity.properties.

The problem is that Velocity is able to load .vm's from my struts.xml file
mappings just fine. It's in my custom template loading code where it throws
the ResourceNotFoundException. Keep in mind that I want to just use the
exact same properties as I have called out in my velocity.properties file.

Here's that code:

        Velocity.init(); // Tried referencing an absolute reference to my
velocity.properties file and that makes no difference.


 System.out.println(Velocity.getProperty("file.resource.loader.path")); //
Allways prints out "." as opposed to "/WEB-INF/" ->

// which is set in my velocity.properties with webapp.resource.loader.path.

        Template template = Velocity.getTemplate( templateName); // Throws
ResourceNotFoundException

Note that I've tried making the templateName absolute, relative, just the
filename.... Makes no difference.

Here's a question, how do I get the exact same VelocityEngine that was
successfully looking up the stuff in my struts.xml mappings? I saw other
posts that said to use VelocityViewServlet - getVelocityEngine() but that
always returned null. Moreover the tools 2.0 docs seem to indicate that that
method is old school.  Seems like if internally Velocity has a singleton of
the engine somewhere that it's using to find all of the other references in
my web.xml, I could just get a hold of that one and use it...

I'll keep reading the new docs for more clues.



On Thu, Dec 4, 2008 at 2:27 PM, carlo latasa <clatasa@gmail.com> wrote:

> Ok - re-read the Velocity docs and am finding that I have to use absolute
> paths for file.resource.loader.path in the velocity.properties. If the path
> is just "." or "WEB-INF" is it relative to the jar location or ?
>
> Either way, I'm still getting ResourceNotFoundException  when trying to
> find my vm (when I know its there and it's permissions allow for reading).
> Could it be an encoding issue?
>
> Here's what my velocity.log sayz:
>
> 2008-12-04 14:16:03,795 - Trying to use logger class
> org.apache.velocity.runtime.log.Log4JLogChute
> 2008-12-04 14:16:03,795 - Using logger class
> org.apache.velocity.runtime.log.Log4JLogChute
> 2008-12-04 14:16:03,795 - Default ResourceManager initializing. (class
> org.apache.velocity.runtime.resource.ResourceManagerImpl)
> 2008-12-04 14:16:03,796 - ResourceLoader instantiated:
> org.apache.velocity.runtime.resource.loader.FileResourceLoader
> 2008-12-04 14:16:03,796 - FileResourceLoader : initialization starting.
> 2008-12-04 14:16:03,796 - Do unicode file recognition:  false
> 2008-12-04 14:16:03,796 - FileResourceLoader : adding path
> '/Users/carlo/ccs/denali/webapp'
> 2008-12-04 14:16:03,796 - FileResourceLoader : initialization complete.
> 2008-12-04 14:16:03,796 - ResourceCache: initialized (class
> org.apache.velocity.runtime.resource.ResourceCacheImpl)
> 2008-12-04 14:16:03,797 - Default ResourceManager initialization complete.
> 2008-12-04 14:16:03,797 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Literal
> 2008-12-04 14:16:03,797 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Macro
> 2008-12-04 14:16:03,798 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Parse
> 2008-12-04 14:16:03,798 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Include
> 2008-12-04 14:16:03,798 - Loaded System Directive:
> org.apache.velocity.runtime.directive.Foreach
> 2008-12-04 14:16:03,807 - Created '20' parsers.
> 2008-12-04 14:16:03,808 - Velocimacro : initialization starting.
> 2008-12-04 14:16:03,809 - Velocimacro : "velocimacro.library" is not set.
> Trying default library: VM_global_library.vm
> 2008-12-04 14:16:03,817 - Velocimacro : Default library not found.
> 2008-12-04 14:16:03,818 - Velocimacro : allowInline = true : VMs can be
> defined inline in templates
> 2008-12-04 14:16:03,818 - Velocimacro : allowInlineToOverride = false : VMs
> defined inline may NOT replace previous VM definitions
> 2008-12-04 14:16:03,818 - Velocimacro : allowInlineLocal = false : VMs
> defined inline will be global in scope if allowed.
> 2008-12-04 14:16:03,818 - Velocimacro : autoload off : VM system will not
> automatically reload global library macros
> 2008-12-04 14:16:03,818 - Velocimacro : Velocimacro : initialization
> complete.
> 2008-12-04 14:16:03,818 - RuntimeInstance successfully initialized.
> 2008-12-04 14:16:32,477 - ResourceManager : unable to find resource
> '/Users/carlo/ccs/denali/webapp/template/dashheader.vm' in any resource
> loader.
>
> Ouch.
>
>
> On Thu, Dec 4, 2008 at 12:20 PM, carlo latasa <clatasa@gmail.com> wrote:
>
>> Thanks both of you for the quick response.
>>
>> So I'm now creating a static instance of the VelocityEngine in my
>> Directive base class and calling init in a static initalizer.
>>
>> Now when getTemplate is called on the velocityEngine instance I get:
>>
>> org.apache.velocity.exception.ResourceNotFoundException: Unable to find
>> resource '/templates/dashheader.vm'
>>     at
>> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:452)
>>     at
>> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:335)
>>     at
>> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)...
>>
>> There's a setting in either velocity.properties or struts.properties that
>> tells the engine where to look. What is that setting?
>>
>> I'm assuming that calling init() on the engine with no params will default
>> to using the velocity.properties file in my WEB-INF/classes dir.
>>
>> Thanks again.
>>
>>
>>
>
>
> --
> Carlo Latasa
> EdgeDriven.com
> Cell: (415) 385-1567
>



-- 
Carlo Latasa
EdgeDriven.com
Cell: (415) 385-1567

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message