ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Conor MacNeill <co...@cortexebusiness.com.au>
Subject Re: AntClassLoader Question (problem?)
Date Thu, 13 Feb 2003 02:25:39 GMT
Christopher Blunck wrote:
> Hi,
> 
> 
> DocumentFactory (or some class that DocumentFactory calls) uses an 
> org.xml.sax.InputSource.  This class is also defined both in rt.jar from
> the JDK distribution as well as in weblogic.jar.  When DocumentFactory tries
> to load InputSource, AntClassLoader looks at "org.xml.sax.InputSource" and 
> says "that's not a system package", and thus it (AntClassLoader) loads the
> class using it's own rule(s) (which really just use the classpath I have
> defined in my build.xml). 

Just to note a little point. The DocumentFactory is not creating the 
InputSource instance. It it were it would have used the SystemLoader (Its 
classloader) and the AntClassLoader would not have got a chance to create 
the class.

> 
> When all the dust settles, I have a DocumentFactory from the JDK and an
> InputSource from weblogic.  The two don't line up, and I get a LinkageError.

Actually you probably have two InputSource classes, one from weblogic and 
one from the JDK. Since the DocumentFactory instance sees both these 
classes, this is the LinkageError.

> 
> I changed the source code for the constructor for AntClassLoader so that it
> does *not* add javax as a system package.  This forced AntClassLoader to
> load the DocumentFactory from weblogic.jar instead of rt.jar, and since 
> InputSource is read from weblogic.jar everything lined up and the my unit
> test ran successfully.

You must be very careful with this :-). The javax package is problematic 
because it is common in both the JDK (system loader) and in app servers but 
with different sets of available classes. What you have done may work but it 
may be just waiting to break. I have had situations where if I ran a test 
twice it would get a linkage error because the classes from the first run 
would not have been GC'd yet. Putting in a delay (or debugging it) and it 
would work.

If you are using JUnit to test code that relies on AppServer classes, it is 
almost always safer to set fork="yes" as Steve suggested.

Conor


Mime
View raw message