tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Konstantin Kolinko <knst.koli...@gmail.com>
Subject Re: Loading Jar files in a particular order on Tomcat 6
Date Sun, 04 Oct 2009 00:13:54 GMT
2009/10/4 Caldarale, Charles R <Chuck.Caldarale@unisys.com>:
>> From: news [mailto:news@ger.gmane.org] On Behalf Of Eric B.
>> Subject: Re: Loading Jar files in a particular order on Tomcat 6
>>
>> I've always noticed that the classloader loads things in alphabetical
>> order.
>
> ??? Which classloader are you referring to?  And by "things", do you mean classes or
jars?  If you're referring to jars, the order of jar processing is determined solely by the
specific classloader instance; it can choose to process the jars in the order they're encountered,
alphabetically, by date/time, or any other means.  Relying on any particular observed behavior
is extremely risky, unless it's defined in the spec.
>
>> Additionally, if it finds the same class in 2 different jars, it only
>> seems to use the class from the first jar.
>
> That is normal behavior for all classloaders.
>


> the order of jar processing is determined solely by the specific classloader instance

I am rather sure that it is an official rule (I must be somewhere
documented [1]),
that jars in a classpath are searched in the order they are specified there.

[1] e.g. in URLClassLoader constructor JavaDoc:
[cite] The URLs will be searched in the order specified [/cite]

Also
http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html
"If a specific order is required then the JAR files can be enumerated
explicitly in the class path."

Certain file systems (e.g. NTFS as far as I know) return file lists in
alphabetical order, but that is all that stands behind that advice of
naming the jar.

There is also an explicit rule that classes in /WEB-INF/classes take
precedence over any jars in /WEB-INF/lib -- see SRV.9.5
"The Web application class loader must load classes from the WEB-INF/ classes
directory first"

Thus the solution in this case is to unpack those jars that must come first.

If those are shared libraries, e.g. in ${catalina.base}/lib, you can
specify an order in catalina.properties

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message