问题
In the past, I have started jstatd via a security policy file, as suggested here: https://stackoverflow.com/a/14930180/1294116
However, in Java 9+, they have removed the tools.jar
file, which means that this solution no longer works. Does anyone know how to get around this? (Currently I am back to getting the error java.security.AccessControlException: access denied ("java.util.PropertyPermission" "java.rmi.server.ignoreSubClasses" "write") ...
)
回答1:
Since Java 9 they moved most (if not all) of the tools.jar
stuff into JDK modules. In this case, the jstatd
tool was moved to its own module: jdk.jstatd. To find out the location (codebase) of this module I ran the following code:
public class Main {
public static void main(String[] args) {
ModuleLayer.boot() // ModuleLayer
.configuration() // Configuration
.findModule("jdk.jstatd") // Optional<ResolvedModule>
.orElseThrow() // ResolvedModule (or throw)
.reference() // ModuleReference
.location() // Optional<URI>
.ifPresentOrElse(System.out::println, () -> System.out.println("Location unknown."));
}
}
Using this command line: ...\jdk-10.0.1\bin\java --add-modules jdk.jstatd Main
This printed out jrt:/jdk.jstatd
. Given this, you could try:
grant codebase "jrt:/jdk.jstatd" {
permission java.security.AllPermission;
};
Note that I'm just guessing here and haven't tested this. If you try this and it doesn't work, please let me know so I can remove this answer.
UPDATE: The following policy file works under Java 11:
grant codebase "jrt:/jdk.jstatd" {
permission java.security.AllPermission;
};
grant codebase "jrt:/jdk.internal.jvmstat" {
permission java.security.AllPermission;
};
回答2:
I found one (questionable) solution to this:
grant {
permission java.security.AllPermission;
};
来源:https://stackoverflow.com/questions/51032095/starting-jstatd-in-java-9