DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=29766>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=29766

Errant space in velocity.properties file can cause classpath resource loader to fail

           Summary: Errant space in velocity.properties file can cause
                    classpath resource loader to fail
           Product: Velocity
           Version: 1.4
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Source
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


I just spent about two hours ferreting out this obnoxious bug, but it should be
trivial to fix.

When configuring my velocity.properties file, I had the lines (taken verbatim
from the documentation):

# specify the resource loaders to use
resource.loader = class 

class.resource.loader.description = Velocity Classpath Resource Loader
class.resource.loader.class =
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
class.resource.loader.cache = false

I was consistently able to load a resource file from the classpath with
getClass().getClassLoader().getResourceAsStream("/my/package/foo.vm") but
Velocity consistently failed with the following stack trace:

Caused by: org.apache.velocity.exception.ResourceNotFoundException: Unable to
find resource '/gov/noaa/nndc/idb/render/vm/field/textField.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)
    at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:813)
    at
org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:285)
    at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:469)
    at gov.noaa.nndc.idb.IdbInitServlet.initVelocity(IdbInitServlet.java:241)
    ... 47 more


After much ado and hacking around, here is some of my debugging code and the output:

System.out.println("Resource Loaders: " +
Velocity.getProperty(RuntimeConstants.RESOURCE_LOADER));
System.out.println("Loader class: " +
Velocity.getProperty("class.resource.loader.class"));            


Resource Loaders: [class ]
Loader class: org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader


It turns out that that there was an errant space in the properties file after
the word "class" and this was causing the classpath resource loader not to be
found. Velocity should trim this whitespace when reading the properties file!

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to