velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Rodriguez <jr...@cs.columbia.edu>
Subject Re: problem reading template file from velocityservlet
Date Fri, 17 Sep 2004 18:18:01 GMT

Ok, I added the suggested lines, slightly modified to be printed on the Web:

  response.getWriter().println("Resource Loaders: " +  Velocity.getProperty(RuntimeConstants.RESOURCE_LOADER)
+ "<BR>");
  response.getWriter().println("Loader class 1: " + Velocity.getProperty("class.resource.loader.class")
+ "<BR>");
  response.getWriter().println("Loader class 2: " + Velocity.getProperty("file.resource.loader.class")
+ "<BR>");

I get the following output:

Resource Loaders: [file]
Loader class 1: null
Loader class 2: org.apache.velocity.runtime.resource.loader.FileResourceLoader

This makes sense to me, because I thought that the FileResourceLoader
class is what is used to load a template file.  Am I wrong?  Is it
actually the ClasspathResourceLoader?

-John

My velocity.properties file is attached below, but it's exactly the same
file as found in ${VELOCITY_HOME}/src/java/org/apache/velocity/runtime/defaults/velocity.properties

/*** attached velocity.properties ***/
runtime.log.logsystem.class = org.apache.velocity.runtime.log.AvalonLogSystem,org.apache.velocity.runtime.log.SimpleLog4JLogSystem
runtime.log = velocity.log
runtime.log.error.stacktrace = false
runtime.log.warn.stacktrace = false
runtime.log.info.stacktrace = false
runtime.log.invalid.reference = true
input.encoding=ISO-8859-1
output.encoding=ISO-8859-1
directive.foreach.counter.name = velocityCount
directive.foreach.counter.initial.value = 1
directive.include.output.errormsg.start = <!-- include error :
directive.include.output.errormsg.end   =  see error log -->
directive.parse.max.depth = 10
resource.loader = file
file.resource.loader.description = Velocity File Resource Loader
file.resource.loader.class =
org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.path = .
file.resource.loader.cache = false
file.resource.loader.modificationCheckInterval = 2
velocimacro.library = VM_global_library.vm
velocimacro.permissions.allow.inline = true
velocimacro.permissions.allow.inline.to.replace.global = false
velocimacro.permissions.allow.inline.local.scope = false
velocimacro.context.localscope = false
runtime.interpolate.string.literals = true
resource.manager.class = org.apache.velocity.runtime.resource.ResourceManagerImpl
resource.manager.cache.class = org.apache.velocity.runtime.resource.ResourceCacheImpl
runtime.introspector.uberspect = org.apache.velocity.util.introspection.UberspectImpl

> Hi John,
>  Saw your stuff a part of which is given at the end...
> you give me the result after plugging in this piece of code
>
> System.out.println("Resource Loaders: " +
> Velocity.getProperty(RuntimeConstants.RESOURCE_LOADER));
> System.out.println("Loader class: " +
> Velocity.getProperty("class.resource.loader.class"));
>
> But before that i have to see your property file. you can change it accordingly to protect
your folks. he he he..
>    i can guess what the problem is...
> ...
>
>
>
> I am sure this is a noob question, but after trying many things from
> newsgroups and web snippets, I have no other ideas.
>
> I am trying to run an example from "Mastering Apache Velocity" where an
> XML file is parsed and used in evaluating the template file.
>
> However, in the code (see line of code below, commented for
> convenience),
> displayxml.vm is not found by the class.  It is currently located in my
> webapp root directory.  cds.xml IS found by the SAXBuilder object when
> instantiated with the absolute pathname.
>
> While investigating, I tried the common suggestion of setting the
> property
> "file.resource.loader.path" to the location of the file, but the same
> error occurs.  The "catalina.out" file says:
>
> org.apache.velocity.exception.ResourceNotFoundException: Unable to find
> resource 'displayxml.vm'
>         at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:458)
>         at
> org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:341)
>         at
> org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:831)
> 	...
>
> In fact I tried all three ways of changing properties, via a custom
> Properties object, via a custom.properties file, and via
> Velocity.setProperty()...same results.
>
> I am not sure exactly what the "." in "file.resource.loader.path"
> refers
> to, however, I believe it's ${CATALINA_HOME}/bin based on an earlier
> bug I
> had with symlinks to jar files.  I've temporarily sidestepped that
> problem
> by copying all jars currently needed to my webapp's /lib directory
>
> I'm currently using Apache Tomcat/4.1.30, JVM version 1.4.2_05-b04,
> OS 2.4.20-gentoo-r2, Velocity 1.4
>
> Any ideas?
>
> /************ ATTACHED CODE ***************/
>
> import javax.servlet.http.*;
> import org.apache.velocity.app.*;
> import org.apache.velocity.*;
> import org.apache.velocity.context.*;
> import org.apache.velocity.servlet.*;
> import org.apache.velocity.exception.*;
> import org.apache.xerces.parsers.*;
> import org.jdom.*;
> import org.jdom.input.*;
>
> public class VelocityServletExample extends VelocityServlet
> {
>   public Template handleRequest( HttpServletRequest request,
> HttpServletResponse response, Context context)
>   {
>      try
>
>
>
> ---------------------------------
> Do you Yahoo!?
> vote.yahoo.com - Register online to vote today!

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


Mime
View raw message