ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: Classloader question
Date Wed, 17 Oct 2001 09:14:57 GMT
On Tue, 09 Oct 2001, Geir Magnusson, Jr. <> wrote:

> I am hoping I am being a dolt, and there is a simple, easy way to
> solve this.

No unfortunately there is not - well at least no non-deprecated way to
solve it, if you use <taskdef reverseloader="true">, it will work with
Ant 1.4 as well, but we don't want to use that.

>     public void setFoo( String foo )
>         throws Exception
>     {
>         ClassLoader classLoader = this.getClass().getClassLoader();

Using context classloaders you would use 

         ClassLoader classLoader = Thread.currentThread().getContextClassLoader();

instead.  This won't work in JDK 1.1 though.

Or if we simply stored the ClassLoader that has been used in the
<taskdef> together with the task instance itself, it would boil down
to a getClassLoader() or something.

Setting the context classloader would help with the factories that are
outside of the tasks control as well (XML parser factories and
whatever), so we should do that anyway.

> I know that this is what we have been talking about - but I needed
> to show that Velocity, factories, singleton pattern, etc have
> nothing to do with it.

No, factories and singletons are just other symptoms of the same
problem, and at least this example and some factory problems could be
solved by the context classloader mechanism.


View raw message