ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Donald <dona...@apache.org>
Subject Re: problems loading resources within classpath
Date Mon, 30 Jul 2001 08:43:34 GMT
On Mon, 30 Jul 2001 18:26, dave young wrote:
> I have been experiencing difficulties whilst attempting to load system
> resources within ant.

What version of ant are you running? Different versions have different 
behaviour ;)

> import java.util.*;
> import java.io.*;
>
> public class p45
> {
>
> public static void main( String[] argv )
> {
> 	loadProperties();
> 	System.out.println( "Hello World!!" );
> }
>
>   protected static Properties loadProperties()
>     {
>         try
>         {
>             // get the properties file from the classpath.
>             Properties p = new Properties();
>             p.load( ClassLoader.getSystemResourceAsStream(
> "my.properties" ) );

As a sidenote you should probably not be doing this as ant makes no 
guarentees about SystemClassLoader. However what you can do to replace it is

getClass().getResourcesAsStream("/my.properties");

> does ant do bizarre things to the class loading that would affect this
> sort of behaviour? 

yes/no/maybe - depends on what you call bizarre and which version you are 
using ;)

Try using above fix and see if that works. Otherwise you may have to get 
latest and greatest ant or wait for a release as I think almost all the 
issues have been worked out in current version of ant.

Cheers,

Pete

*-----------------------------------------------------*
| "Faced with the choice between changing one's mind, |
| and proving that there is no need to do so - almost |
| everyone gets busy on the proof."                   |
|              - John Kenneth Galbraith               |
*-----------------------------------------------------*

Mime
View raw message