8

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?

Qwerty
  • 83
  • 1
  • 6
  • 4
    `javac -bootclasspath` works as before when targeting JDK 8 or older .`java -Xbootclasspath/a` to append to the boot class path works as before. – Alan Bateman Jan 08 '18 at 10:53
  • 3
    I guess you mean `-Xbootclasspath/a` JVM option which I could confirm is still present in the java options of 9.0.1. Or maybe i misunderstood the question? – Naman Jan 08 '18 at 10:55

2 Answers2

8

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.

Naman
  • 27,789
  • 26
  • 218
  • 353
Anjana
  • 873
  • 7
  • 22
  • 2
    Thank you. I was using -Xbootclasspath/p . Shall change it to -Xbootclasspath/a . Hope there is no difference other than that the former appends to the beginning of the classpath and the later at the end. – Qwerty Jan 08 '18 at 11:02
  • 2
    I am having same issue with java 11 and even -Xbootclasspath/a is not working. Does anyone know any workaround please.. – JagKum Nov 28 '18 at 23:10
0

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