I need to debug something happening inside JDK 1.8 classes. I'm trying to use the endorsed dir mechanism mentioned here, but doesn't seem to be working for me. This is what I did (on Windows):
- copied the
javax.swing.plaf.basic.BasicListUIclass source code into<JDK_HOME>/jre/lib/endorsed/javax/swing/plaf/basic/ Modified the class code, adding:
static { System.out.println("REPLACED BasicListUI"); }I expect this to cause the message to be printed as soon as the class is loaded.
cd to
<JDK_HOME>/jre/lib/endorsedand runjavac javax/swing/plaf/basic/BasicListUI. This results in theBasicListUI.classfile generated in the same dir as the source file.wrote, and compiled this program:
import javax.swing.plaf.basic.BasicListUI; public class t { public static void main(String args[]) { System.out.println(System.getProperty("java.endorsed.dirs")); System.out.println(BasicListUI.class.getResource("BasicListUI.class")); } }executed program with
java t. I don't see theREPLACED BasicListUImessage, and the output of the program is:C:\Program Files\Java\jdk1.8.0_40\jre\lib\endorsed jar:file:/C:/Program%20Files/Java/jdk1.8.0_40/jre/lib/rt.jar!/javax/swing/plaf/basic/BasicListUI.class
Also, if I run:
$ java -verbose t | grep BasicListUI
The output is:
[Loaded javax.swing.plaf.basic.BasicListUI from C:\Program Files\Java\jdk1.8.0_40\jre\lib\rt.jar] jar:file:/C:/Program%20Files/Java/jdk1.8.0_40/jre/lib/rt.jar!/javax/swing /plaf/basic/BasicListUI.class
What am I missing?
Ah, found the problem. The classes have to be packaged in a jar file. so, added
jar cvf rt.jar javax/swing/plaf/basic/BasicListUI.class