velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From laredotornado <laredotorn...@gmail.com>
Subject Re: Trouble finding velocity.properties in a jar
Date Fri, 22 Jul 2011 13:15:48 GMT

Accessing the properties in another way worked ...

		final InputStream resourceStream =
this.getClass().getClassLoader().getResourceAsStream("velocity.properties");

Thanks, - Dave



Nathan Bubna wrote:
> 
> I would do two things (the first of which, you have probably done).
> 1) double-check that the build process for the JAR is correctly
> putting the velocity.properties file into the root of the jar and that
> the jar is in the classpath  2) try finding it elsewhere in the
> classloader heirarchy:
> 
> InputStream stream =
> Thread.currentThread().getContextClassLoader().getResourceAsStream("velocity.properties");
> if (stream == null) {
>   stream =
> ThisClass.class.getClassLoader().getResourceAsStream("velocity.properties");
>   if (stream == null) {
>       stream = ThisClass.class.getResourceAsStream("velocity.properties");
>       if (stream == null) {
>          throw new RuntimeException("WTF?  i'm not sure the resource
> is really there.");
>       }
>   }
> }
> 
> On Thu, Jul 21, 2011 at 9:37 AM, laredotornado <laredotornado@gmail.com>
> wrote:
>>
>> Hi,
>>
>> I'm using Java 1.6, Velocity 1.6.2.  I have a Maven JAR project, in which
>> the "velocity.properties" gets packaged at the root of the JAR.  When I
>> include this JAR in other projects, I'm not able to initialize velocity,
>> using ...
>>
>>                VelocityEngine ve = new VelocityEngine();
>>                final InputStream resourceStream =
>> Thread.currentThread().getContextClassLoader().getResourceAsStream("velocity.properties");
>>                final Properties velocityProps = new Properties();
>>                velocityProps.load(resourceStream);
>>                ve.init( velocityProps );
>>
>> 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.
>> Thanks, - Dave
>> --
>> View this message in context:
>> http://old.nabble.com/Trouble-finding-velocity.properties-in-a-jar-tp32108932p32108932.html
>> Sent from the Velocity - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
>> For additional commands, e-mail: user-help@velocity.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Trouble-finding-velocity.properties-in-a-jar-tp32108932p32115227.html
Sent from the Velocity - User mailing list archive at Nabble.com.


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


Mime
View raw message