You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by John Harris <Jo...@nurs.utah.edu> on 2001/05/21 23:49:24 UTC

Resource loader problems

I'm trying to get ClasspathResourceLoader working. I had this working as documented with a previous release of velocity-1.1-dev, but I can't get it to work right with velocity-1.1-rc1 (or velocity-1.0.1).

I'm running tomcat 3.2.1 with velocity-1.1-rc1.

The webapp is configured as follows:
1. webapp/velocity.properties file is
resource.loader = class
class.resource.loader.description = Velocity Classpath Resource Loader
class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
2. webapp/WEB-INF/lib/sample.vm
    webapp/WEB-INF/lib/velocity-1.1-rc1.jar
3. webapp/WEB-INF/web.xml - has appropriate info for SampleServlet

The only way I can get velocity to find and serve sample.vm is by starting tomcat from webapp/WEB-INF/lib directory, and not jarring sample.vm...any other combinations refuse to work with the same "handleRequest(Context) returned null - no template selected!" exception.

Any ideas?

John Harris


Re: Resource loader problems

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
John Harris wrote:
> 
> I'm trying to get ClasspathResourceLoader working. I had this working as documented with a previous release of velocity-1.1-dev, but I can't get it to work right with velocity-1.1-rc1 (or velocity-1.0.1).
> 
> I'm running tomcat 3.2.1 with velocity-1.1-rc1.
> 
> The webapp is configured as follows:
> 1. webapp/velocity.properties file is
> resource.loader = class
> class.resource.loader.description = Velocity Classpath Resource Loader
> class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
> 2. webapp/WEB-INF/lib/sample.vm
>     webapp/WEB-INF/lib/velocity-1.1-rc1.jar
> 3. webapp/WEB-INF/web.xml - has appropriate info for SampleServlet
> 
> The only way I can get velocity to find and serve sample.vm is by starting tomcat from webapp/WEB-INF/lib directory, and not jarring sample.vm...any other combinations refuse to work with the same "handleRequest(Context) returned null - no template selected!" exception.
> 
> Any ideas?

Oh - on second thought, the following may not apply to you - I am
confused about what bits you are using and where - but here's something
to consider :

If you are using the SampleServlet.java from the
examples/servlet_example directory was *changed* to totally ignore the
velocity.properties file - 

The reason is to remove this bit of mysticism for people just getting
the hang of servlets, getting all the pieces together.  So
SampleServlet.java does everything internally, adding the webapp root as
it's template path.

I'll add a SampleServlet2.java that does the right thing re properties.

Sorry about that, but I hope you can understand the need to try and
elminate the confusion, and I apologize for not thinking it through.

geir
-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re: Resource loader problems

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
John Harris wrote:
> 
> I'm trying to get ClasspathResourceLoader working. I had this working as documented with a previous release of velocity-1.1-dev, but I can't get it to work right with velocity-1.1-rc1 (or velocity-1.0.1).
> 
> I'm running tomcat 3.2.1 with velocity-1.1-rc1.
> 
> The webapp is configured as follows:
> 1. webapp/velocity.properties file is
> resource.loader = class
> class.resource.loader.description = Velocity Classpath Resource Loader
> class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
> 2. webapp/WEB-INF/lib/sample.vm
>     webapp/WEB-INF/lib/velocity-1.1-rc1.jar
> 3. webapp/WEB-INF/web.xml - has appropriate info for SampleServlet
> 
> The only way I can get velocity to find and serve sample.vm is by starting tomcat from webapp/WEB-INF/lib directory, and not jarring sample.vm...any other combinations refuse to work with the same "handleRequest(Context) returned null - no template selected!" exception.
> 
> Any ideas?

No :)  I'll try it - nothing should have changed in this going from
1.1-dev to 1.1-rc1

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re: Resource loader problems

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
John Harris wrote:
> 
> I'm trying to get ClasspathResourceLoader working. I had this working as documented with a previous release of velocity-1.1-dev, but I can't get it to work right with velocity-1.1-rc1 (or velocity-1.0.1).
> 
> I'm running tomcat 3.2.1 with velocity-1.1-rc1.
> 
> The webapp is configured as follows:
> 1. webapp/velocity.properties file is
> resource.loader = class
> class.resource.loader.description = Velocity Classpath Resource Loader
> class.resource.loader.class = org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
> 2. webapp/WEB-INF/lib/sample.vm
>     webapp/WEB-INF/lib/velocity-1.1-rc1.jar
> 3. webapp/WEB-INF/web.xml - has appropriate info for SampleServlet
> 
> The only way I can get velocity to find and serve sample.vm is by starting tomcat from webapp/WEB-INF/lib directory, and not jarring sample.vm...any other combinations refuse to work with the same "handleRequest(Context) returned null - no template selected!" exception.

Ok - I verified that the ClasspathResourceLoader is working.  Here is
what I did :

1) made a webapp velexample, with the ususal WEB-INF trimmings.  Put the
new vel-1.1-rc1.jar into lib.
2) Made a jar containing the sample.vm :

   jar cv template.jar sample.vm

  and put that in WEB-INF/lib

3) ALTERED the SampleServlet.java in examples/sample_servlet1 - removed
the loadConfiguration method, which didn't read the properties file in.

4) put a web.xml into the WEB-INF directory that looks like :
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>

<servlet>
    <servlet-name>SampleServlet2</servlet-name>
    <servlet-class>SampleServlet2</servlet-class>
    <init-param>
      <param-name>properties</param-name>
      <param-value>/velocity.properties</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
</web-app>


5) added a velocity.properties to the velexample directory

resource.loader = class
class.resource.loader.class =
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader


6) started up tomcat, and all works fine.

Note that the velocity.log file goes into the directory that you started
tomcat from - I will make another servlet example that has all the
pieces correctly.

Sorry about the mixup.

geir



-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."

Re: Resource loader problems and Re: can't load my own properties file using tomcat

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
I think both of these problems were caused by the changes to
servlet_example1 to have it self-configure.  In the process, of course,
it ignores any external properties file.

I added a new servlet_example2, which uses a velocity.properties, and
has examples on how to work with the ClasspathResourceLoader and the
FileResourceLoader

Note that this example is *not* identical to the original
servlet_example1 either, as that had very little value-add for new
users, and resulted in quite a bit of confusion.

The new servlet_example2 is checked into both the CVS HEAD, so it will
appear in the nightly snapshot, as well as the 1.1 branch.  There are a
few more issues before we mint a rc2, so get from CVS or the nightly.

It was only tested under linux, so if anyone can verify that all is good
under Windows, that would be great.

geir

-- 
Geir Magnusson Jr.                           geirm@optonline.net
System and Software Consulting
Developing for the web?  See http://jakarta.apache.org/velocity/
"still climbing up to the shoulders..."