Qwerty
Qwerty

Reputation: 93

How to add a jar to the boot classpath in java 9

In my application that runs on java 8, I am using -bootclasspath:p to add a jar to the boot classpath. In java 9, the option is removed. What is the alternative to do the same in java 9?

Upvotes: 9

Views: 9585

Answers (2)

-bootclasspath:p add classes from jar to the begin of default bootstrap class path (prepended). It isn't longer supported in JVM 9 or greater.

-bootclasspath:a add classes from jar to the end of default bootstrap class path (appended). This option is supported in JVM 9 or greater. https://docs.oracle.com/cd/E15289_01/JRCLR/optionx.htm#i1021218

In my case when I declare variables in this order:

JAVA_OPTS="$SOME_OPT"

JAVA_OPTS="-javaagent:../agent.jar -Xbootclasspath/a:../agent-boot.jar $JAVA_OPTS"

I catch classNotFoundException. And when I reverse order:

JAVA_OPTS="-javaagent:../agent.jar -Xbootclasspath/a:../agent-boot.jar $JAVA_OPTS"

JAVA_OPTS="$SOME_OPT"

ClassNotFound exception disappear.

Upvotes: 0

Anjana
Anjana

Reputation: 883

You may use -Xbootclasspath/a. Please refer to the release notes which states:-

The boot class path has been mostly removed in this release. The java -Xbootclasspath and -Xbootclasspath/p options have been removed.

The javac -bootclaspath option can only be used when compiling to JDK 8 or older. The system property sun.boot.class.path has been removed.

Deployments that rely on overriding platform classes for testing purposes with -Xbootclasspath/p will need to changed to use the --patch-module option that is documented in JEP 261.

The -Xbootclasspath/a option is unchanged.

Upvotes: 9

Related Questions