Patching a bug in the JDK for an individual applic

2019-09-04 17:19发布

问题:

I have established through another question that the problem I'm having with my JavaFX program is due to a bug in the JDK that is not going to be fixed anytime soon. I was even informed that the bug is in PrismTextLayout.

So having found the source code for this, how would I implement some kind of patch which would allow me to fix this bug for my application only. Obviously if I did fix the problem, I would contribute it back to a future JDK, but for now I just want a quick fix.

I thought a simple google search for patching the JDK, etc would turn up heaps of information, but actually, virutally nothing.

Can someone, if not explain how to patch, at least point me in the right direction for some documentation on this subject.

回答1:

Patching a JavaFX class without actually building the whole JDK or JavaFX is quite easy. I did that for example for the class SVGPath some time ago.

  1. Extract the class source from the source zip which is distributed with the JDK and add it to your project in the correct folder according to its package name. In my case this would be javafx/scene/shape/SVGPath.java.
  2. Explicitly add ${JDK_HOME}/jre/lib/ext/jfxrt.jar to your classpath.
  3. Run your program with the java options "-Djava.ext.dirs=". This procedure is essential to be able to override the existing classes in jfxrt.jar.

That is it.