Are you "forking" the junit test? That could have an effect on the
classloader. Check the classpath that you are providing to <junit>. You
can do this by creating it first as a <path>, assigning it a refid,
generating a <property> using the refid attribute, and then <echo>'ing the
contents of the property you just set. See if the classpath contains the
resource you are looking for.
K.C.
> -----Original Message-----
> From: Matthew Cooper [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, March 22, 2001 6:48 PM
> To: [EMAIL PROTECTED]
> Subject: JUnit task : getResourceAsStream problems
>
>
> I am using ant 1.3 junit 3.5 and sun jdk 1.3 for linux. If i
> use the junit
> task to run a test under ant, the code cannot load the
> resource I specify - I
> just get null returned from ...
>
> System.out.println("System classloader");
>
> System.out.println(ClassLoader.getSystemResourceAsStream(RESOU
RCE_NAME));
>
> ...or...
>
>
> ClassLoader classLoader = Thread.currentThread()
> .getContextClassLoader();
> System.out.println(" classloader="+classLoader);
>
> System.out.println(classLoader.getResourceAsStream(RESOURCE_NAME));
>
>
> If i run the unit test from the command line with something like...
>
> java -cp
> ../build/classes:../build/test/classes/:lib/junit.jar...etc...
> junit.textui.TestRunner MyTest
>
> then the system classloader works and finds the resource
> (although I cannot
> get the current Thread's class loader to work).
>
> In case its relevant, I am trying to load the resource in a
> static code
> that gets run when my class loads.
>
> Can anyone help???
>
> Thanks, Matty.
>