Search code examples
javajvmjvm-arguments

JVM Xbootclasspath with single classfile


I want to replace the custom JVM Throwable class with my own implementation by adding it to the bootclasspath. My argument looks like this: -Xbootclasspath/p:/home/skappler/Programming/**/target/classes/java/lang

The lang folder contains the Throwable.class

When I start my program with -verbose:class I get:

[Path /home/skappler/Programming/**/target/classes/java/lang]
[Opened /opt/java/jre/lib/rt.jar]
...
[Loaded java.lang.Throwable from /opt/java/jre/lib/rt.jar]

Why doesn't it use my custom class?


Solution

  • When you give a directory, it has to be a base directory from which all packages are a sub-directory like it does with classpath. e.g. if the JVM is looking for java./lang.Throwable, it will look for java/lang/Throwable.class under the directory you give.

    Try instead

    -Xbootclasspath/p:/home/skappler/Programming/**/target/classes/
    

    BTW http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html states

    Do not deploy applications that use this option to override a class in rt.jar because this violates the Java Runtime Environment binary code license.

    An alternative is to provide an agent which instruments the Throwable class. e.g. replaces it with your own.

    Another option is to add a lib/endorsed directory with a jar of the classes you want.

    Whether these options also violate the license agreement or not, I cannot say.