Yousef Amar
Yousef Amar

Reputation: 661

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) {
    }
}

Upvotes: 1

Views: 1640

Answers (2)

zeroimpl
zeroimpl

Reputation: 2846

In Java 8+ the class is moved to sun.security.tools.keytool.Main and you access it via javac --add-exports=java.base/sun.security.tools.keytool=ALL-UNNAMED

Upvotes: 0

omajid
omajid

Reputation: 15233

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.

Upvotes: 2

Related Questions