velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Cohen <sco...@javactivity.org>
Subject Re: Which flavor of Velocity to use?
Date Mon, 29 Dec 2008 01:23:46 GMT
Thanks, Nathan.  This sounds like the right approach.

Do you mean org.apache.velocity.tools.view.servlet.WebappLoader?
I don't find a WebappResourceLoader.  Assuming you do mean the 
WebappLoader, then I'm having a little trouble getting it to initialize 
properly.  Will your method work with the Singleton approach?

My initialization code is as follows:

    public static void initVelocity(ServletContext ctx)
    throws VelocityInitializationException
    {
       
        Velocity.setProperty( RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
          "org.apache.velocity.runtime.log.Log4JLogChute" );

        Velocity.setProperty("runtime.log.logsystem.log4j.logger",
                        "Velocity");
       
        Velocity.setProperty("resource.loader.class",
                "org.apache.velocity.tools.view.servlet.WebappLoader");
       
        Velocity.setApplicationAttribute("javax.servlet.ServletContext", 
ctx);


        try {
            Velocity.init();
        } catch (Exception e) {
            throw new VelocityInitializationException(e);
        }
    }

Yet when I run it I see the following in the log:

2008-12-28 19:12:08,166 [main] DEBUG Velocity  - ResourceLoader 
instantiated: org.apache.velocity.runtime.resource.loader.FileResourceLoader

and when I go to access my templates they, of course, can't be found.

What am I doing wrong?

Steve

Nathan Bubna wrote:
> ...
>
> Yeah, i don't think you really need the VelocityViewServlet.  (Note
> that the VelocityServlet class is deprecated).   But so long as you
> are running in a webapp container like Tomcat and have access to a
> ServletContext, you can use the WebappResourceLoader (from
> VelocityTools 2) to load templates from your web context.  Just
> remember to put the ServletContext object in your VelocityEngine (or
> singleton) application attributes before you initialize it:
>
> VelocityEngine engine = new VelocityEngine();
> engine.setApplicationAttribute("javax.servlet.ServletContext",
> theServletContext);
> engine.init(properties);
> ...
>
>   
>> Thanks.
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
>>     
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
>
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Mime
View raw message