java-7javasun

How to I access this particular class?


The class in question is sun.security.tools.KeyTool and I'm using OpenJDK 7. I keep getting "cannot find symbol" though, and I'm no Java expert so I can't figure out through documentation why that could be or if it's gone. Any ideas?

Exact error message:

Main.java:1: error: cannot find symbol
import sun.security.tools.KeyTool;
                         ^
  symbol:   class KeyTool
  location: package sun.security.tools

Code:

import sun.security.tools.KeyTool;

public class Main {
    public static void main(String[] args) {
    }
}

Solution

  • Try using javac -XDignore.symbol.file ....

    By default javac restricts the classes it exposes to users. This generally helps users avoid accidentally depending on (unsupported) classes that are not public Java API but happen to be available in the current JRE/JDK. The list of "safe" classes is described in ct.sym file. The ignorel.symbol.file system property tells javac to ignore that file and make use of all classes available in the JDK/JRE.

    And make sure you add tools.jar, where this class is defined to the classpath for javac.