Patch or override an implementation of a core Java 10 class

Looks like a solution is possible using java agents, as per this question

Replace a class within the Java class library with a custom version


I needed to do this but I was launching Java from C through the JNI interface (instead of the command line). Just transposing the command line args to JavaVMOptions didn't work. Instead it all goes in one arg as follows:

JavaVMOption options[N_ARGS] = { 0 };
options[0].optionString = "--patch-module=javafx.runtime=patch.jar";

It took a lot of digging to figure this out, so hope it saves someone else some time.


Once again, Alan gives the best answer as a comment. :) Quote:

--patch-module javafx.runtime=patch.jar is the right way to override classes in this module

If you need to "override" a class in a platform module, use --patch-module to do that. If that drags in additional dependencies, make sure to make them readable with --add-reads.