velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Trouble finding velocity.properties in a jar
Date Thu, 21 Jul 2011 17:31:07 GMT
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.

-chris


Mime
View raw message