简体   繁体   English

在Tomcat 5上控制WEB-INF / lib中jar的类路径排序?

[英]Control the classpath ordering of jars in WEB-INF/lib on Tomcat 5?

I have a legacy web app running in Tomcat 5.0. 我有一个在Tomcat 5.0中运行的遗留Web应用程序。

This web app has two jars in WEB-INF/lib , let's say Foo-2.0.jar and Bar-2.0.jar . 这个Web应用程序在WEB-INF / lib中有两个jar,比如说Foo-2.0.jarBar-2.0.jar Bar-2.0.jar actually includes a Foo-1.0.jar inside of it. Bar-2.0.jar实际上包含了一个Foo-1.0.jar Bar is also a dead project, meaning no upgrading, no source, but still important to the application. Bar也是一个死的项目,意味着没有升级,没有来源,但对应用程序仍然很重要。

The latest release of this application requires Foo-2.0.jar for some other stuff. 该应用程序的最新版本需要Foo-2.0.jar来处理其他一些内容。 Having both Foo-1.0.jar and Foo-2.0.jar in the classpath creates a conflict, specifically a ClassDefNotFound type of error, where a class that was later added in 2.0 cannot be found in 1.0, etc. 在类路径中同时具有Foo-1.0.jarFoo-2.0.jar会产生冲突,特别是ClassDefNotFound类型的错误,其中稍后在2.0中添加的类无法在1.0中找到,等等。

In Eclipse, the simple solution is to right click on your Project , click Properties > Java Built Path > Order and Export and to move Foo-2.0.jar above Bar-2.0.jar so it's resolved first. 在Eclipse中,简单的解决方案是右键单击您的Project ,单击Properties > Java Built Path > Order and Export并将Foo-2.0.jar移到Bar-2.0.jar之上,以便首先解析它。

How does one accomplish this type of classpath ordering for jars in WEB-INF/lib in Tomcat? 如何在Tomcat的WEB-INF / lib中为jar实现这种类型的路径排序?

Tomcat 5's classloading precedence for webapps is roughly as follows: first the bootstrap/system ( JRE/lib , then Tomcat's internal classes), then the webapp libraries (first WEB-INF/classes , then WEB-INF/lib ), then the common libraries (first Tomcat/common , then Tomcat/lib ) and finally the webapp-shared libraries ( Tomcat/shared ). Tomcat 5的 webapps 类加载优先级大致如下:首先是bootstrap / system( JRE/lib ,然后是Tomcat的内部类),然后是webapp库(首先是WEB-INF/classes ,然后是WEB-INF/lib ),然后是常见的库(首先是Tomcat/common ,然后是Tomcat/lib ),最后是webapp-shared库( Tomcat/shared )。

So to get Foo-2.0.jar loaded before Bar-2.0.jar , best what you can do is to move Bar-2.0.jar from WEB-INF/lib to Tomcat/common or Tomcat/shared . 因此,要 Bar-2.0.jar 之前加载Foo-2.0.jar ,最好的办法是将Bar-2.0.jarWEB-INF/libTomcat/commonTomcat/shared

The JAR's aren't loaded in alphabetic order of their name. JAR未按名称的字母顺序加载。 At least, there's no spec which says that. 至少,没有规范说明这一点。 Renaming them to change the alphabetical filename order makes no sense. 重命名它们以更改按字母顺序排列的文件名顺序是没有意义的。

Strip Foo-1.0.jar out of Bar-2.0.jar . Bar-2.0.jar中剥离Foo-1.0.jar As it is, it's just trouble waiting to happen both for development(need to fudge the dev. environments) and for deployment. 事实上,等待开发(需要捏造开发环境)和部署都很麻烦。

将Foo-1.0.jar放到$ CATALINE_HOME / common / endorsed(或者在Foo-2.0.jar之后将加载它的任何其他位置)。

You don't, as this feature isn't available in Tomcat. 您没有,因为Tomcat中没有此功能。 If both Foo-1.0.jar and Foo-2.0.jar are needed in the classpath at the same time, you will need some major classpath reorganization. 如果同时在类路径中同时需要Foo-1.0.jar和Foo-2.0.jar,则需要进行一些主要的类路径重组。

If Bar-2.0 can work with Foo-2.0, then the best thing to do would be to rebuild Bar-2.0 yourself without a Foo-1.0.jar inside of it. 如果Bar-2.0可以与Foo-2.0一起使用,那么最好的办法就是在没有Foo-1.0.jar的情况下自己重建Bar-2.0。

It is possible to set the Class-Path in the mainfest of the jar. 可以在jar的mainfest中设置Class-Path。 http://java.sun.com/developer/Books/javaprogramming/JAR/basics/manifest.html I can't really promise it will solve the problem, but can be worth a try. http://java.sun.com/developer/Books/javaprogramming/JAR/basics/manifest.html我不能保证它会解决问题,但值得一试。

To have Foo-2.0.jar before Bar-2.0.jar, update the Bar-2.0.jar with the content of Foo-2.0.jar (overwrite already contained .class)and delete Foo-2.0.jar from the war. 要在Bar-2.0.jar之前使用Foo-2.0.jar,请使用Foo-2.0.jar的内容更新Bar-2.0.jar(覆盖已包含的.class)并从war中删除Foo-2.0.jar。

-cp A.jar:B.jar has the effect, that content of A.jar is like a layer over B.jar. -cp A.jar:B.jar有效,A.jar的内容就像是B.jar上的一层。 So you get the same effect with overwriting B.jar's content with A.jar's. 所以你用A.jar的覆盖B.jar的内容会得到同样的效果。

This is a bit hacky but might work. 这有点hacky但可能会奏效。 Change the name of Foo-2.0.jar to be alphabetically ahead of Bar-2.0.jar, say AFoo-2.0.jar. 将Foo-2.0.jar的名称改为按字母顺序排在Bar-2.0.jar之前,比如说AFoo-2.0.jar。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM