Skip to Content.
Sympa Menu

shibboleth-dev - Re: class loading order

Subject: Shibboleth Developers

List archive

Re: class loading order


Chronological Thread 
  • From: Chad La Joie <>
  • To:
  • Subject: Re: class loading order
  • Date: Mon, 22 Aug 2005 08:40:37 -0400
  • Organization: UIS - Project Sentinel

I'm not sure why you start out by talking about the Tomcat class loading mechanism and then switch to the build stuff.

In ant, tasks that take paths using things like pathelement or classpath elements just compose a single class path BEFORE the parent operation runs. So, the ordering of items generally doesn't matter. When the JVM kicks off it just searches the whole classpath for the class.

Now, I said it generally doesn't matter which order elements appear in. When it does matter is when you have multiple classes with the same name but differing signatures, at which point the JVM just uses whichever it finds first. Don't do this, it's bad (and the extension FAQ says not to do it). :)

So, are you seeing an error, if so what is it?

Tom Scavo wrote:
According to the Tomcat documentation, a web application loads classes
and other resources in the following order:

1. Bootstrap classes of your JVM
2. System class loader classes (described above)
3. /WEB-INF/classes of your web application
4. /WEB-INF/lib/*.jar of your web application
etc.

So the classloader attempts to resolve unpacked classes and resources
under /WEB-INF/classes *before* looking in JAR files under
/WEB-INF/lib.

Thus the build classpath in build.xml is more-or-less correct:

<path id="build.path">
<pathelement path="${classpath}" />
<pathelement location="${build}" />
<fileset dir="${custom}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${endorsed}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${libdir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="${buildlibs}">
<include name="**/*.jar" />
</fileset>
</path>

We could quibble about the order of the JAR files, but the build
directory is searched first, which is most important. (Btw, why is
${custom} in this classpath? This seems like a bug.)

Also in build.xml, when running unit tests, the following classpath is used:

<classpath>
<fileset dir="${custom.libs}">
<include name="*.jar"/>
</fileset>
<filelist refid="test.path"/>
</classpath>

where

<path id="test.path">
<path refid="build.path"/>
<pathelement location="${tests}"/>
</path>

This results in the following search order:

1) Extension JARs
2) Shibboleth classes
3) Shibboleth JARs
4) Extension classes

which doesn't seem right. Shouldn't the order be:

1) Extension classes
2) Extension JARs
3) Shibboleth classes
4) Shibboleth JARs

I'm assuming that Extension classes and JARs should be searched before
Shibboleth classes and JARS, which seems reasonable. However, in
extension-build.xml the build classpath is as follows:

<!-- Shibboleth Libraries -->
<classpath refid="build.path" />

<!-- Shibboleth Classes -->
<classpath>
<pathelement location="${build}" />
</classpath>

<!-- Extension libraries -->
<classpath>
<fileset dir="${ext.lib}">
<include name="**/*.jar" />
</fileset>
</classpath>

That's not right since 1) the second classpath element ${build} is
redundant, and 2) Shibboleth classes and libraries are searched before
extension libraries. The order should be, I think, just the opposite:

<!-- Extension libraries -->
<classpath>
<fileset dir="${ext.lib}">
<include name="**/*.jar" />
</fileset>
</classpath>

<!-- Shibboleth Classes and Libraries -->
<classpath refid="build.path" />

Moreover, when running unit tests in extension-build.xml, the
following pathelement should be inserted at the *beginning* of the
above list:

<classpath>
<pathelement location="${ext.classes}" />
</classpath>

Otherwise JUnit will not be able to find the unit test class files.

Let me know what you think.

Tom

--
Chad La Joie 315Q St. Mary's Hall
Project Sentinel 202.687.0124



Archive powered by MHonArc 2.6.16.

Top of Page