Starting jstatd in Java 9+

谁说胖子不能爱 提交于 2020-01-13 08:16:30

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!