velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shinobu Kawai <shinobu.ka...@gmail.com>
Subject Re: [TOOLS] LayoutServlet finds layouts, but not templates in CP
Date Wed, 13 Oct 2004 03:51:31 GMT
Hi Timo,

>  Received a question from a colleague trying to load templates from the
> classpath (i.e. inside a jar in WEB-INF/lib) and getting: Unable to find
> resource errors.
> 
> I've been using the classpath resource loader in another project without
> problems, but not for the main template -- just the layout.
> 
> I modified the velocity-tools layout example app to test.
> I see the same problem. :-(
> 
> I made a jar with these two files and added to the Velocity Tools layout
> example:
> cptimo.vm          -> "Howdy from inside the template.jar"
> layout/cplayout.vm -> "classpath layout $screencontent"
> 
> http://localhost/layout/index.vm?layout=cplayout.vm -> works great
> http://localhost/layout/cptimo.vm -> fails:

## snip

> I had to add commons-logging.jar to get the servlet to init (Marino/Nathan
> -- is there a reason that isn't included?)
Are you specifying CommonsLogLogSystem as the LogSystem class? 
Otherwise, I don't think you need it.  At least I didn't need it.  :)

## snip

> Any ideas?
The root of the problem is that
java.util.jar.JarFile#getJarEntry(String name) will not return
anything if a "/" is leading the name.  This causes
org.apache.catalina.loader.WebappClassLoader#findResourceInternal(String
name, String path) to return null.  This causes
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader#getResourceStream(String
name) to return null.  This causes your ResourceNotFoundException.

If we fix ClasspathResourceLoader so it trims the leading "/"s like in
WebappLoader, it will work.  I'm not sure if this is the right fix,
though.  It might just be a Tomcat issue.  I'll attach the patch
anyways.

Best regards,
-- Shinobu Kawai

-- 
Shinobu Kawai <shinobu.kawai@gmail.com>

Mime
View raw message