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

发布于 2024-08-16 18:39:34 字数 700 浏览 4 评论 0原文

我有一个在 Tomcat 5.0 中运行的旧版 Web 应用程序。

此 Web 应用程序在 WEB-INF/lib 中有两个 jar,例如 Foo-2.0.jarBar-2.0.jarBar-2.0.jar 实际上包含一个 Foo-1.0.jar 。 Bar也是一个死项目,意味着没有升级,没有源代码,但对应用程序仍然很重要。

该应用程序的最新版本需要 Foo-2.0.jar 来实现其他一些功能。类路径中同时存在 Foo-1.0.jarFoo-2.0.jar 会产生冲突,特别是 ClassDefNotFound 类型的错误,其中后来在2.0中添加的类在1.0中找不到,等等。

在Eclipse中,简单的解决方案是右键单击您的项目,单击属性> > Java 构建路径 > 订购和导出并将 Foo-2.0.jar 移至 Bar-2.0.jar 上方,以便首先解决该问题。

如何在 Tomcat 的 WEB-INF/lib 中完成此类 jar 的类路径排序?

I have a legacy web app running in Tomcat 5.0.

This web app has two jars in WEB-INF/lib, let's say Foo-2.0.jar and Bar-2.0.jar. Bar-2.0.jar actually includes a Foo-1.0.jar inside of it. Bar is also a dead project, meaning no upgrading, no source, but still important to the application.

The latest release of this application requires Foo-2.0.jar for some other stuff. 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.

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.

How does one accomplish this type of classpath ordering for jars in WEB-INF/lib in Tomcat?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

謸气贵蔟 2024-08-23 18:39:34

Tomcat 5 的 webapp 类加载优先级大致如下:首先是 bootstrap/system(JRE/lib,然后是 Tomcat 的内部类),然后是 webapp 库(首先是 WEB-INF/classes,然后是 WEB-INF/ lib),然后是公共库(首先是 Tomcat/common,然后是 Tomcat/lib),最后是 web 应用程序共享库(Tomcat/shared )。

因此,要在 Bar-2.0.jar 之前加载 Foo-2.0.jar,最好将 Bar- 2.0.jarWEB-INF/libTomcat/commonTomcat/shared

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).

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.

The JAR's aren't loaded in alphabetic order of their name. At least, there's no spec which says that. Renaming them to change the alphabetical filename order makes no sense.

青芜 2024-08-23 18:39:34

Bar-2.0.jar 中剥离 Foo-1.0.jar。事实上,开发(需要修改开发环境)和部署都是麻烦。

Strip Foo-1.0.jar out of Bar-2.0.jar. As it is, it's just trouble waiting to happen both for development(need to fudge the dev. environments) and for deployment.

世俗缘 2024-08-23 18:39:34

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

Put Foo-1.0.jar to $CATALINE_HOME/common/endorsed (or any other place where it will be loaded after Foo-2.0.jar).

━╋う一瞬間旳綻放 2024-08-23 18:39:34

您不需要,因为 Tomcat 中不提供此功能。如果类路径中同时需要 Foo-1.0.jar 和 Foo-2.0.jar,则需要进行一些主要的类路径重组。

如果 Bar-2.0 可以与 Foo-2.0 一起工作,那么最好的办法就是自己重建 Bar-2.0,而不在其中包含 Foo-1.0.jar。

You don't, as this feature isn't available in 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.

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.

南笙 2024-08-23 18:39:34

可以在 jar 的 mainfest 中设置类路径。 http://java.sun.com/developer/Books/ javaprogramming/JAR/basics/manifest.html
我不能真正保证它会解决问题,但值得一试。

It is possible to set the Class-Path in the mainfest of the jar. 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.

趴在窗边数星星i 2024-08-23 18:39:34

要在 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 的效果是,A.jar 的内容就像 B.jar 上的一层。因此,用 A.jar 覆盖 B.jar 的内容会得到相同的效果。

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.

-cp A.jar:B.jar has the effect, that content of A.jar is like a layer over B.jar. So you get the same effect with overwriting B.jar's content with A.jar's.

下壹個目標 2024-08-23 18:39:34

这有点 hacky 但可能有效。将 Foo-2.0.jar 的名称更改为按字母顺序位于 Bar-2.0.jar 之前,例如 AFoo-2.0.jar。

This is a bit hacky but might work. Change the name of Foo-2.0.jar to be alphabetically ahead of Bar-2.0.jar, say AFoo-2.0.jar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文