Java 9 中的endorsed 目录如何替换?

How do you replace endorsed directory in Java 9?

在 Java 8 和更早版本中存在使用认可目录 (java.endorsed.dirs) 的机制,它是覆盖 JDK 内部实现的库集合。

如何在 Java-9 中解决这个问题?作为认可的目录在哪里删除?

在 JDK 9 中,您可以使用 upgradeable modules 或将 JAR 文件放在类路径中。

Java 9 migration guide 状态:

The java.endorsed.dirs system property and the lib/endorsed directory are no longer present. The javac compiler and java launcher will exit if either one is detected.

如果其中任何一个存在,您最终会发现错误:

<JAVA_HOME>/lib/endorsed is not supported. Endorsed standards and
standalone APIs in modular form will be supported via the concept of
upgradeable modules. Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

这些认可的标准覆盖机制已被删除以获得 Modular Run-Time Images,现在将使用模块化图像。

A modular image is composed of modules rather than JAR files. Going forward, endorsed standards and standalone APIs are supported in modular form only, via the concept of upgradeable modules.

我也遇到了同样的问题,Java 高于 8 的版本不受 Tomcat 9 的支持。 请查看 bin/catalina.sh 了解更多信息。

JAVA_ENDORSED_DIRS (Optional) Lists of of colon separated directories containing some jars in order to allow replacement of APIs created outside of the JCP (i.e. DOM and SAX from W3C). It can also be used to update the XML parser implementation. This is only supported for Java <= 8. Defaults to $CATALINA_HOME/endorsed.

这是一个特定的解决方案,但可能会被推广。在系统版本上:macOS 10.14.6 (18G3020) 内核版本:Darwin 18.7.0 我安装了 OpenJDK 64 位服务器 VM(构建 13.0.2+8,混合模式,共享)和 java_ee_sdk-8u1。

我在执行xjc的时候遇到了这个错误:

[foo@bar bin 14:47:27] sudo ./xjc
-Djava.endorsed.dirs=./../modules/endorsed is not supported. Endorsed standards and standalone APIs
in modular form will be supported via the concept of upgradeable modules.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.enter code here

我编辑了 ~/glassfish5/glassfish/bin/xjc 中的最后一行以删除 -Djava.endorsed.dirs 位: 之前

exec "$JAVA" -Djava.endorsed.dirs="$AS_INSTALL_LIB/endorsed" -cp "$AS_INSTALL_LIB/webservices-osgi.jar:$AS_INSTALL_LIB/javax.xml.rpc-api.jar:$AS_INSTALL_LIB/jaxb-osgi.jar" com.sun.tools.xjc.Driver "$@"

之后

exec "$JAVA" -cp "$AS_INSTALL_LIB/webservices-osgi.jar:$AS_INSTALL_LIB/javax.xml.rpc-api.jar:$AS_INSTALL_LIB/jaxb-osgi.jar" com.sun.tools.xjc.Driver "$@"

之后 ~/glassfish5/glassfish/bin/xjc 按预期工作