endorsed dir mechanism not working?

1.2k views Asked by At

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):

  1. copied the javax.swing.plaf.basic.BasicListUI class source code into <JDK_HOME>/jre/lib/endorsed/javax/swing/plaf/basic/
  2. 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.

  3. cd to <JDK_HOME>/jre/lib/endorsed and run javac javax/swing/plaf/basic/BasicListUI. This results in the BasicListUI.class file generated in the same dir as the source file.

  4. 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"));
        }
    }
    
  5. executed program with java t. I don't see the REPLACED BasicListUI message, 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?

1

There are 1 answers

1
Roberto Attias On BEST ANSWER

Ah, found the problem. The classes have to be packaged in a jar file. so, added

  1. jar cvf rt.jar javax/swing/plaf/basic/BasicListUI.class