velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Bubna <nbu...@gmail.com>
Subject Re: Trouble finding velocity.properties in a jar
Date Thu, 21 Jul 2011 17:36:32 GMT
On Thu, Jul 21, 2011 at 10:31 AM, Christopher Schultz
<chris@christopherschultz.net> wrote:
> Dave,
>
> On 7/21/2011 12:37 PM, laredotornado wrote:
>>               final InputStream resourceStream =
>> Thread.currentThread().getContextClassLoader().getResourceAsStream("velocity.properties");
>
> Should that have a leading "/" in the path?
>
>> The above dies because the "resourceStream" is null.  Any ideas how I
>> reference this file?  Keep in mind that it is packaged within the JAR.
>
> If you have an exotic ClassLoader hierarchy, you may be getting the
> wrong ClassLoader -- one that isn't expecting to load yourjar.jar or
> have one of it's parent ClassLoaders do it.
>
> Nathan's suggestion to try CurrentClass.class.getResourceAsStream after
> CurrentClass.class.getClassLoader.getResourceAsStream just makes your
> code harder to read and doesn't add anything: Class.getResourceAsStream
> already delegates to Class.getClassLoader.getResourceAsStream.

i've wondered about that, but never bothered to investigate.  i
cribbed that code from Tools' ClassUtils class, which i derived from
somebody else's apparently redundant code.  wanna change ClassUtils to
remove the redundancy? :)


> -chris
>
>

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


Mime
View raw message