How do you replace endorsed directory in Java 9?

31,463

Solution 1

In JDK 9, you can use upgradeable modules or put the JAR files on the classpath.

The Java 9 migration guide states:

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.

You would end up finding the error if any of these exists as :

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

These endorsed-standards override mechanism was removed to attain Modular Run-Time Images and would now use the modular image.

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.

Solution 2

This is a specific solution but can probably be generalized. On System Version: macOS 10.14.6 (18G3020) Kernel Version: Darwin 18.7.0 I have OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing) and java_ee_sdk-8u1 installed.

I encountered this error when executing 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

I edited the last line in ~/glassfish5/glassfish/bin/xjc to remove the -Djava.endorsed.dirs bit: BEFORE

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 "$@"

AFTER

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 "$@"

After which ~/glassfish5/glassfish/bin/xjc worked as expected

Share:
31,463

Related videos on Youtube

keiki
Author by

keiki

Updated on July 17, 2022

Comments

  • keiki
    keiki almost 2 years

    In Java 8 and prior there exists the mechanism to use an endorsed directory(java.endorsed.dirs), which is a collection of libraries which overrides JDK internal implementations.

    How can I solve this in Java-9? As endorsed dirs where removed there?

    • Anders
      Anders over 3 years
      You don't, you use modules instead. Problems with endorsed and classpath is fixed with modules, becuase of several reasons.
  • Impulse The Fox
    Impulse The Fox about 6 years
    "Java versions higher than 8 are not supported by Tomcat 9" This is not true, look at the official site. It clearly says "8 and later".
  • Bruno Sponsorship
    Bruno Sponsorship over 4 years
    @IsanRodriguezTrimiño Hahaha!! me too!!
  • weeheavy
    weeheavy almost 4 years
    Hahahaha, me too, Java goes Brrrrr now.
  • Anders
    Anders almost 4 years
    What is not supported after Java 8 is the switch -Djava.endorsed.dirs=.... It is not Tomcat that isn't supporting Java 9 and later.