java 类路径和背书目录之间的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/380411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 12:10:22  来源:igfitidea点击:

Difference between classpath and endorsed directory

jarclasspathjavaendorsed

提问by Henrik Aasted S?rensen

Does anyone know what the difference is between adding an appropriate JAR-file (eg. Apache XALAN) to a JRE's endorsed directory and adding it to the application's classpath?

有谁知道将适当的 JAR 文件(例如 Apache XALAN)添加到 JRE 的认可目录与将其添加到应用程序的类路径之间有什么区别?

Is it possible to take a jar-file that can be added to the endorsed lib and instead add it to the classpath?

是否可以将 jar 文件添加到已认可的库中并将其添加到类路径中?

回答by Rolf

Tecnically you probaly can do that, but the difference is that the jar files in the endorsed directory are loaded by the bootstrap classloader, which is probably not the same classloader as the one that loads your jars from the classpath.

从技术上讲,您可能可以做到这一点,但不同之处在于,背书目录中的 jar 文件由引导类加载器加载,这可能与从类路径加载 jar 的类加载器不同。

There is a classic XML problem with the Xerces and Xalan XML implementations which are out in the endorsed directory. Because newer applications sometimes require newer versions of both libraries, and the classes have the same names, there is a classpath problem.

Xerces 和 Xalan XML 实现存在一个典型的 XML 问题,它们位于已背书目录中。因为较新的应用程序有时需要两个库的较新版本,并且类具有相同的名称,所以存在类路径问题。

You can replace the Xerces and Xalan libraries in the endorsed dir (backup your old ones!) but that can possibly screw up other applications which use the same JRE installation.

您可以替换认可目录中的 Xerces 和 Xalan 库(备份您的旧库!),但这可能会搞砸使用相同 JRE 安装的其他应用程序。

I've even seen this problem within 1 application where one library depends on one version, and another library depends on another version of xerces. Very troublesome, and there's no "general approach" to this, or at least none that I found.

我什至在 1 个应用程序中看到过这个问题,其中一个库依赖于一个版本,另一个库依赖于另一个版本的 xerces。非常麻烦,并且没有对此的“通用方法”,或者至少我没有找到。

There are some interesting articles easily found by Google on this, try to find one which best matches your situation or problem.

谷歌很容易在这方面找到一些有趣的文章,尝试找到最适合您的情况或问题的文章。