ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: Ant,Java,JUnit and class initialization ?
Date Wed, 11 Apr 2001 10:48:00 GMT
Kai Bartels <> wrote:

> The "first" class of the server ("Supervisor") now has a public
> static field describing it's sole instance, so I have a starting
> point from which to wander off into the server. But when I try to
> access this field from my test class the class Supervisor is
> initialized a second time and the fields value is (of course) (reset
> to) null; I can't find the server. I tried direct access to the
> static fild (Supervisor.lastInstance) and introspection - no
> difference.

Your Supervisor class is loaded more than once.  Singleton like
patterns work only on a per classloader basis, that is you get one
instance of your Supervisor per classloader.

As you are setting the classpath for both <java> and <junit>
explicitely, Ant will use a new classloader for each of both.  Now we
have three classloader involved, the system classloader,
classloader-java and classloader-junit for the two tasks.

Your testcase sees the static field of the Supervisor class loaded by
classloader-junit, which is not the same class that has been
initialized in classloader-java.

The only workaround I see is to put all necessary archives into the
system classpath and don't define any classpath in your build file at
all (neither for the java nor the junit task).


View raw message