You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Tim Colson <tc...@cisco.com> on 2004/10/12 17:55:10 UTC
[TOOLS] LayoutServlet finds layouts, but not templates in CP
Howdy folks -
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:
org.apache.velocity.exception.ResourceNotFoundException: Unable to find
resource '/cptimo.vm'
at
org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(Resour
ceManagerImpl.java:458)
at
org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(Resourc
eManagerImpl.java:341)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java
:831)
at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java
:813)
at
org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.ja
va:285)
at
org.apache.velocity.tools.view.servlet.VelocityViewServlet.getTemplate(Unkno
wn Source)
------
I'm running inside Tomcat 4.0.6, using the HEAD of velocity
tools-examples-layout app.
I had to add commons-logging.jar to get the servlet to init (Marino/Nathan
-- is there a reason that isn't included?)
I added the template.jar from above to WEB-INF/lib and this to the
velocity.properties
#---------------------------------------------------------------------------
-
# RESOURCE loaders
#---------------------------------------------------------------------------
-
resource.loader = class, webapp
#
# ClasspathResourceLoader
class.resource.loader.description = Velocity Classpath Resource Loader
class.resource.loader.class =
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
# WebappResourceLoader
webapp.resource.loader.description = Velocity Webapp Resource Loader
webapp.resource.loader.class=org.apache.velocity.tools.view.servlet.WebappLo
ader
webapp.resource.loader.path=/WEB-INF/pages/,/
# Should be set to TRUE everywhere but LOCAL workstation
webapp.resource.loader.cache=false
-----------------
Any ideas?
Thanks,
Timo
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: [TOOLS] LayoutServlet finds layouts, but not templates in CP
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi,
> And here's the patch to do so.
Where did it go? I'll try again.
Best regards,
-- Shinobu Kawai
--
Shinobu Kawai <sh...@gmail.com>
Re: [TOOLS] LayoutServlet finds layouts, but not templates in CP
Posted by Shinobu Kawai <sh...@gmail.com>.
Hi,
> 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.
You know what? I think it's not the ClasspathResourceLoader's
responsibility. It's just doing its stuff. A better place to trim the
leading "/"s is where the template path is being created, namely
o.a.v.t.view.servlet.VelocityViewServlet#handleRequest(...).
And here's the patch to do so.
Best regards,
-- Shinobu Kawai
--
Shinobu Kawai <sh...@gmail.com>
RE: [TOOLS] LayoutServlet finds layouts, but not templates in CP
Posted by Tim Colson <tc...@cisco.com>.
> Are you specifying CommonsLogLogSystem as the LogSystem class?
> Otherwise, I don't think you need it. At least I didn't need it.
I didn't spec anything, just grabbed the examples\layout.war and dropped it
into tomcat 4.0.6 and it complained about commons logging. YMMV
> java.util.jar.JarFile#getJarEntry(String name) will not return
> anything if a "/" is leading the name.
> .... This causes your ResourceNotFoundException.
> It might just be a Tomcat issue. I'll attach the patch
> anyways.
Thanks Shinobu -- that worked great. :-)
Cheers,
Timo
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org
Re: [TOOLS] LayoutServlet finds layouts, but not templates in CP
Posted by Shinobu Kawai <sh...@gmail.com>.
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 <sh...@gmail.com>