You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Rasmus Larsen <ko...@gmail.com> on 2009/10/02 22:30:18 UTC
Loading Jar files in a particular order on Tomcat 6
I'm working on a web application where I have dependencies on two
different jars containing two different versions of the same class.
The jar files are supplied by an external vendor and cannot be
changed.
I've created a custom class loader, which first first tries to load
classes from a specific set of jars, and if that fails it just loads
the class in the standard manner. This makes it possible to ensure
that a specific set of jar files are always used first. This solves my
problem.
However, I was wondering if there was an easier way.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Loading Jar files in a particular order on Tomcat 6
Posted by Martin Gainty <mg...@hotmail.com>.
Larsen
Keeping more than one version of the same package and class will cause excessive Administrative work
Maven Build Environments will allow you to deploy a specific package/class and version to a profile
maven allows you to compile/install and deploy the same package/class with a different version for Development, QA and Production profiles
http://maven.apache.org
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
> Date: Sun, 4 Oct 2009 13:02:39 +0200
> Subject: Re: Loading Jar files in a particular order on Tomcat 6
> From: kolibriasdf@gmail.com
> To: users@tomcat.apache.org
>
> 2009/10/4 Leon Rosenberg <ro...@googlemail.com>:
> > On Sun, Oct 4, 2009 at 1:00 AM, Eric B. <eb...@hotmail.com> wrote:
> >> "Caldarale, Charles R" <Ch...@unisys.com> wrote in message
> > Back to the original post,
> > why don't you simply patch (maybe automatically with ant) the jar file
> > containing the 'old' version of the class and remove it?
>
> The jar files are provided and signed by an external vendor.
>
> > You won't be able to keep two different versions of a class in the
> > same classloader anyway.
>
> I want to use the newest version only, of course. Normally, I would
> simply place the jar with the newest versions first in the classpath.
> But the tomcat server has no such control, instead it just loads jar
> files from the WEB-INF/lib directory, which means that the order is
> based on the OS filesystem.
>
> Apparently, there is no easy way to control the classpath for web
> applications in Tomcat, so instead I have to make a custom classloader
> that does loads classes from the jar files in a controlled order.
>
> - Rasmus
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/171222986/direct/01/
RE: Loading Jar files in a particular order on Tomcat 6
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Konstantin Kolinko [mailto:knst.kolinko@gmail.com]
> Subject: Re: Loading Jar files in a particular order on Tomcat 6
>
> 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.
Correct; this is what I was referring to as "normal behavior". What is not in spec is the order in which jars are placed in the classpath when the classpath is constructed internally by the classloader itself.
> 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.
NTFS is the only one I'm aware of that does it, and its ordering is not case-sensitive, if that's a concern. In most environments, the sorting is done by whatever shell program is displaying the contents of the directory.
> Thus the solution in this case is to unpack those jars that
> must come first.
Painful, but workable.
> If those are shared libraries, e.g. in ${catalina.base}/lib, you can
> specify an order in catalina.properties
Much more controllable.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Loading Jar files in a particular order on Tomcat 6
Posted by Konstantin Kolinko <kn...@gmail.com>.
2009/10/4 Caldarale, Charles R <Ch...@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
RE: Loading Jar files in a particular order on Tomcat 6
Posted by "Caldarale, Charles R" <Ch...@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.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Loading Jar files in a particular order on Tomcat 6
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Rasmus Larsen [mailto:kolibriasdf@gmail.com]
> Subject: Re: Loading Jar files in a particular order on Tomcat 6
>
> Just to clarify, the Jars have nothing to do with SpringSource.
Sorry, my mistake; I was confusing this thread with Bocalinda's.
Contacting the vendor or doing your own repackaging would likely be less work and maintenance than doing your own classloader.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Loading Jar files in a particular order on Tomcat 6
Posted by Rasmus Larsen <ko...@gmail.com>.
2009/10/4 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Leon Rosenberg [mailto:rosenberg.leon@googlemail.com]
>> Subject: Re: Loading Jar files in a particular order on Tomcat 6
>>
>> No, you can just overwrite setclasspath.sh and put the 'first' jar
>> into the first place of the classpath manually.
>
> ??? These are jars deployed with the webapp, located in WEB-INF/lib; putting them on the system classplath will cause no end of grief.
>
Yeah, I've come to the conclusion that a custom class loader is the way to go.
>> On a side note, I would have a serious discussion about the quality of
>> their jars with the vendor(s). Simply put: one class can only be
>> located in one jar, everything else is unacceptable :-)
>
> Indeed; I'm quite surprised SpringSource would distribute something that way. I wonder if they have an alternative, non-conflicting packaging available.
>
Just to clarify, the Jars have nothing to do with SpringSource.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Loading Jar files in a particular order on Tomcat 6
Posted by Leon Rosenberg <ro...@googlemail.com>.
On Sun, Oct 4, 2009 at 4:23 PM, Caldarale, Charles R
<Ch...@unisys.com> wrote:
>> From: Leon Rosenberg [mailto:rosenberg.leon@googlemail.com]
>> Subject: Re: Loading Jar files in a particular order on Tomcat 6
>>
>> No, you can just overwrite setclasspath.sh and put the 'first' jar
>> into the first place of the classpath manually.
>
> ??? These are jars deployed with the webapp, located in WEB-INF/lib; putting them on the system classplath will cause no end of grief.
I assume removing them from WEB-INF/lib, and putting them both on the
system-wide classpath in the defined order will do the job. I'm not
saying this is
how it should be done, but having same classes in multiple jars aren't as well.
However, I second your suggestion of repackaging. This will probably
be the least possible effort.
regards
Leon
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Loading Jar files in a particular order on Tomcat 6
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Leon Rosenberg [mailto:rosenberg.leon@googlemail.com]
> Subject: Re: Loading Jar files in a particular order on Tomcat 6
>
> No, you can just overwrite setclasspath.sh and put the 'first' jar
> into the first place of the classpath manually.
??? These are jars deployed with the webapp, located in WEB-INF/lib; putting them on the system classplath will cause no end of grief.
> On a side note, I would have a serious discussion about the quality of
> their jars with the vendor(s). Simply put: one class can only be
> located in one jar, everything else is unacceptable :-)
Indeed; I'm quite surprised SpringSource would distribute something that way. I wonder if they have an alternative, non-conflicting packaging available.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Loading Jar files in a particular order on Tomcat 6
Posted by Leon Rosenberg <ro...@googlemail.com>.
On Sun, Oct 4, 2009 at 1:02 PM, Rasmus Larsen <ko...@gmail.com> wrote:
> 2009/10/4 Leon Rosenberg <ro...@googlemail.com>:
>> On Sun, Oct 4, 2009 at 1:00 AM, Eric B. <eb...@hotmail.com> wrote:
>>> "Caldarale, Charles R" <Ch...@unisys.com> wrote in message
>> Back to the original post,
>> why don't you simply patch (maybe automatically with ant) the jar file
>> containing the 'old' version of the class and remove it?
>
> The jar files are provided and signed by an external vendor.
>
>> You won't be able to keep two different versions of a class in the
>> same classloader anyway.
>
> I want to use the newest version only, of course. Normally, I would
> simply place the jar with the newest versions first in the classpath.
> But the tomcat server has no such control, instead it just loads jar
> files from the WEB-INF/lib directory, which means that the order is
> based on the OS filesystem.
No, you can just overwrite setclasspath.sh and put the 'first' jar
into the first place of the classpath manually.
On a side note, I would have a serious discussion about the quality of
their jars with the vendor(s). Simply put: one class can only be
located in one jar, everything else is unacceptable :-)
regards
Leon
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Loading Jar files in a particular order on Tomcat 6
Posted by Rasmus Larsen <ko...@gmail.com>.
2009/10/4 Leon Rosenberg <ro...@googlemail.com>:
> On Sun, Oct 4, 2009 at 1:00 AM, Eric B. <eb...@hotmail.com> wrote:
>> "Caldarale, Charles R" <Ch...@unisys.com> wrote in message
> Back to the original post,
> why don't you simply patch (maybe automatically with ant) the jar file
> containing the 'old' version of the class and remove it?
The jar files are provided and signed by an external vendor.
> You won't be able to keep two different versions of a class in the
> same classloader anyway.
I want to use the newest version only, of course. Normally, I would
simply place the jar with the newest versions first in the classpath.
But the tomcat server has no such control, instead it just loads jar
files from the WEB-INF/lib directory, which means that the order is
based on the OS filesystem.
Apparently, there is no easy way to control the classpath for web
applications in Tomcat, so instead I have to make a custom classloader
that does loads classes from the jar files in a controlled order.
- Rasmus
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Loading Jar files in a particular order on Tomcat 6
Posted by Leon Rosenberg <ro...@googlemail.com>.
On Sun, Oct 4, 2009 at 1:00 AM, Eric B. <eb...@hotmail.com> wrote:
> "Caldarale, Charles R" <Ch...@unisys.com> wrote in message
> news:99C8B2929B39C24493377AC7A121E21F84054C1188@USEA-EXCH8.na.uis.unisys.com...
>> From: Rasmus Larsen [mailto:kolibriasdf@gmail.com]
>> Subject: Loading Jar files in a particular order on Tomcat 6
>>
>> I'm working on a web application where I have dependencies on two
>> different jars containing two different versions of the same class.
>
>> Ugly, at best.
>
Back to the original post,
why don't you simply patch (maybe automatically with ant) the jar file
containing the 'old' version of the class and remove it?
You won't be able to keep two different versions of a class in the
same classloader anyway.
regards
Leon
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Loading Jar files in a particular order on Tomcat 6
Posted by "Eric B." <eb...@hotmail.com>.
"Caldarale, Charles R" <Ch...@unisys.com> wrote in message
news:99C8B2929B39C24493377AC7A121E21F84054C1188@USEA-EXCH8.na.uis.unisys.com...
> From: Rasmus Larsen [mailto:kolibriasdf@gmail.com]
> Subject: Loading Jar files in a particular order on Tomcat 6
>
> I'm working on a web application where I have dependencies on two
> different jars containing two different versions of the same class.
> Ugly, at best.
> I've created a custom class loader, which first first tries to load
> classes from a specific set of jars, and if that fails it just loads
> the class in the standard manner.
> Unless you have explicit control over the classpath used by each
> classloader in the hierarchy (which you don't), a custom classloader
> is pretty much the only way to handle this.
I've always noticed that the classloader loads things in alphabetical order.
Additionally, if it finds the same class in 2 different jars, it only seems
to use the class from the first jar.
I would suggest just trying to rename the "important" jars if possible with
a prefix of something like aaa_<jarname>.jar to force the classloader to
pick it up first.
Just a thought....
Eric
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Loading Jar files in a particular order on Tomcat 6
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Rasmus Larsen [mailto:kolibriasdf@gmail.com]
> Subject: Loading Jar files in a particular order on Tomcat 6
>
> I'm working on a web application where I have dependencies on two
> different jars containing two different versions of the same class.
Ugly, at best.
> I've created a custom class loader, which first first tries to load
> classes from a specific set of jars, and if that fails it just loads
> the class in the standard manner.
Unless you have explicit control over the classpath used by each classloader in the hierarchy (which you don't), a custom classloader is pretty much the only way to handle this.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Loading Jar files in a particular order on Tomcat 6
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Rasmus,
On 10/2/2009 4:30 PM, Rasmus Larsen wrote:
> I've created a custom class loader, which first first tries to load
> classes from a specific set of jars, and if that fails it just loads
> the class in the standard manner. This makes it possible to ensure
> that a specific set of jar files are always used first. This solves my
> problem.
>
> However, I was wondering if there was an easier way.
FWIW, I would generalize the ClassLoader a bit so that it treats the
JARs uniformly. For instance, always search for classes in the JARs in
order alphabetically by JAR file name (but not path). That way, you can
name your JARs like "1_log4j.jar" and "2_other_log4j.jar" or whatever.
It wasn't entirely clear how you implemented your ClassLoader but it
sounded like it might be /very/ specific to your exact requirements,
today. Doing something like alphabetical resolution by file name might
be re-usable in some other insane environment.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAkrPqN8ACgkQ9CaO5/Lv0PBLeQCffqFtEir44arwerzOUf36Vyo+
9EoAn0hw6cytspxELVKAkEe/idvuGpq6
=LvcO
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Loading Jar files in a particular order on Tomcat 6
Posted by Konstantin Kolinko <kn...@gmail.com>.
One more way:
You can use VirtualWebappLoader
http://tomcat.apache.org/tomcat-6.0-doc/api/org/apache/catalina/loader/VirtualWebappLoader.html
It adds the listed classpath entries to the webapp classloader.
I do not know, whether it appends or prepends them, and as that is not
documented it can be different between versions, but the following is
certain: the libraries listed in virtualClasspath attribute are added
in that very order with respect to each other.
So, you can remove those conflicting libraries from WEB-INF/lib, e.g.
move them to /WEB-INF/lib2, and add them in that particular order that
you need.
Note, that you can reference Java properties in any values in the context file.
E.g. ${catalina.base}/webapps/myapp/WEB-INF/lib2/mylib.jar should work.
Wildcards, e.g. *.jar, are not supported.
The downside is that VirtualWebappLoader is not so widely used, and so
there may be not so much experience with it, but you may give it a
try.
Best regards,
Konstantin Kolinko
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org