You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by "Charles N. Harvey III" <ch...@alloy.com> on 2004/08/28 00:31:54 UTC

classpath resource loader

Hello,
This is my first time using the classpath resourceloader.  And I can't
seem to find the template.  What is the path that I use when calling
my template?  Do I just put in the name directly?

Velocity.getTemplate( "myTemplate.vm" );

Or do I put in some path?

Velocity.getTemplate( "com/mycompany/myTemplate.vm" );

I'm really lost here.  Any help is greatly appreciated.

Thanks a lot.


Charlie



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


Re: classpath resource loader

Posted by Shinobu Kawai <sh...@ieee.org>.
Hi Charlie,

> ERROR [2004-08-30 11:10:03,602] (TemplateEmailLogic.java:82) - 
> java.lang.NullPointerException
>     at 
> org.apache.velocity.runtime.RuntimeInstance.getLoaderNameForResource(RuntimeInstance.java:883)
>     at 
> org.apache.velocity.runtime.RuntimeSingleton.getLoaderNameForResource(RuntimeSingleton.java:350)
>     at org.apache.velocity.app.Velocity.resourceExists(Velocity.java:509)
>     at 
> com.alloyinc.shopetc.logic.TemplateEmailLogic.createMessageBody(TemplateEmailLogic.java:54)
Here's where it's failing:
881:    public String getLoaderNameForResource( String resourceName )
882:    {
883:        return resourceManager.getLoaderNameForResource( resourceName );
884:    }
Looks like your resourceManager is not set.  Better check your
initialization process.

> Here is what I have in my config file:
> 
> resource.manager.class = 
> org.apache.velocity.runtime.resource.ResourceManagerImpl
> resource.manager.cache.class = 
> org.apache.velocity.runtime.resource.ResourceCacheImpl
> resource.loader = class
> class.resource.loader.class = 
> org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
> class.resource.loader.description = Velocity Classpath Resource Loader
Looks fine...  Is that everything there?  And how are you initializing
Velocity?

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <shinobu@ieee.org, shinobu@computer.org>




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


Re: #set and hashes

Posted by Shinobu Kawai <sh...@ieee.org>.
Hi Larry,

> Can anyone tell me why this example from 
> http://jakarta.apache.org/velocity/user-guide.html#Set won't work in 
> Velocity 1.4?
> 
> #set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"}) ## Map
> 
> Do I have to download and build the latest CVS head to use this feature?
diff-ing the source tells me "yes, you do".
    cvs diff -r VEL_1_4 src/java/org/apache/velocity/runtime/parser/Parser.jjt

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <shinobu@ieee.org, shinobu@computer.org>




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


#set and hashes

Posted by La...@MSCsoftware.com.
Can anyone tell me why this example from 
http://jakarta.apache.org/velocity/user-guide.html#Set won't work in 
Velocity 1.4?

#set( $monkey.Map = {"banana" : "good", "roast beef" : "bad"}) ## Map

Do I have to download and build the latest CVS head to use this feature?


Larry Siden, IBS consultant, Viper team
x72612

Re: classpath resource loader

Posted by Will Glass-Husain <wg...@forio.com>.
Hi Charles,

Just as a side note.  I've found the ClassPathResourceLoader to be a bit
idiosyncratic.   Caching doesn't work, for example.  Check out the bug
report here:

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22419

WILL

----- Original Message ----- 
From: "Charles N. Harvey III" <ch...@alloy.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Monday, August 30, 2004 8:14 AM
Subject: Re: classpath resource loader


> Ok.  Its not because my template can't be found, it can.  Its because
> I can't seem to get the ResourceLoaderName:
>
>
> ERROR [2004-08-30 11:10:03,602] (TemplateEmailLogic.java:82) -
> java.lang.NullPointerException
>     at
>
org.apache.velocity.runtime.RuntimeInstance.getLoaderNameForResource(Runtime
Instance.java:883)
>     at
>
org.apache.velocity.runtime.RuntimeSingleton.getLoaderNameForResource(Runtim
eSingleton.java:350)
>     at org.apache.velocity.app.Velocity.resourceExists(Velocity.java:509)
>     at
>
com.alloyinc.shopetc.logic.TemplateEmailLogic.createMessageBody(TemplateEmai
lLogic.java:54)
>
>
> Here is what I have in my config file:
>
> resource.manager.class =
> org.apache.velocity.runtime.resource.ResourceManagerImpl
> resource.manager.cache.class =
> org.apache.velocity.runtime.resource.ResourceCacheImpl
> resource.loader = class
> class.resource.loader.class =
> org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
> class.resource.loader.description = Velocity Classpath Resource Loader
>
>
> Is there something I am doing wrong?  Some kind of bad syntax, spelling?
>
> Any help is much appreciated.
>
>
> Charlie
>
>
> Shinobu Kawai said the following on 8/29/2004 8:59 PM:
>
> >Hi Charlie,
> >
> >
> >
> >>This is my first time using the classpath resourceloader.  And I can't
> >>seem to find the template.  What is the path that I use when calling
> >>my template?  Do I just put in the name directly?
> >>
> >>Velocity.getTemplate( "myTemplate.vm" );
> >>
> >>Or do I put in some path?
> >>
> >>Velocity.getTemplate( "com/mycompany/myTemplate.vm" );
> >>
> >>
> >Where are you placing the template?  All you have to do, is make sure
> >that the ClassLoader can access the template as a resource.
> >
http://jakarta.apache.org/velocity/api/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.html
> >
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResourceAsStream(java.lang.String)
> >
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String)
> >
> >Best regards,
> >-- Shinobu Kawai
> >
> >--
> >Shinobu Kawai <shinobu@ieee.org, shinobu@computer.org>
> >
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>


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


Re: classpath resource loader

Posted by "Charles N. Harvey III" <ch...@alloy.com>.
Ok.  Its not because my template can't be found, it can.  Its because
I can't seem to get the ResourceLoaderName:


ERROR [2004-08-30 11:10:03,602] (TemplateEmailLogic.java:82) - 
java.lang.NullPointerException
    at 
org.apache.velocity.runtime.RuntimeInstance.getLoaderNameForResource(RuntimeInstance.java:883)
    at 
org.apache.velocity.runtime.RuntimeSingleton.getLoaderNameForResource(RuntimeSingleton.java:350)
    at org.apache.velocity.app.Velocity.resourceExists(Velocity.java:509)
    at 
com.alloyinc.shopetc.logic.TemplateEmailLogic.createMessageBody(TemplateEmailLogic.java:54)


Here is what I have in my config file:

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


Is there something I am doing wrong?  Some kind of bad syntax, spelling?

Any help is much appreciated.


Charlie


Shinobu Kawai said the following on 8/29/2004 8:59 PM:

>Hi Charlie,
>
>  
>
>>This is my first time using the classpath resourceloader.  And I can't
>>seem to find the template.  What is the path that I use when calling
>>my template?  Do I just put in the name directly?
>>
>>Velocity.getTemplate( "myTemplate.vm" );
>>
>>Or do I put in some path?
>>
>>Velocity.getTemplate( "com/mycompany/myTemplate.vm" );
>>    
>>
>Where are you placing the template?  All you have to do, is make sure
>that the ClassLoader can access the template as a resource.
>    http://jakarta.apache.org/velocity/api/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.html
>    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResourceAsStream(java.lang.String)
>    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String)
>
>Best regards,
>-- Shinobu Kawai
>
>--
>Shinobu Kawai <shinobu@ieee.org, shinobu@computer.org>
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
>
>  
>


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


Re: classpath resource loader

Posted by Shinobu Kawai <sh...@ieee.org>.
Hi Charlie,

> This is my first time using the classpath resourceloader.  And I can't
> seem to find the template.  What is the path that I use when calling
> my template?  Do I just put in the name directly?
> 
> Velocity.getTemplate( "myTemplate.vm" );
> 
> Or do I put in some path?
> 
> Velocity.getTemplate( "com/mycompany/myTemplate.vm" );
Where are you placing the template?  All you have to do, is make sure
that the ClassLoader can access the template as a resource.
    http://jakarta.apache.org/velocity/api/org/apache/velocity/runtime/resource/loader/ClasspathResourceLoader.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResourceAsStream(java.lang.String)
    http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#getResource(java.lang.String)

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <shinobu@ieee.org, shinobu@computer.org>




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