我们在通过远程连接jmx的过程中遇到了问题,我们通过ProcessBuilder程序运行了一个作业。
param ="-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=A.B.C.D -Dcom.sun.management.jmxremote.port=9875 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false "
ProcessBuilder pb = new ProcessBuilder("java", param,"-cp", jobArtifact.getAbsolutePath());
pb.command().add("org.springframework.batch.core.launch.support.CommandLineJobRunner");
final Process process = processBuilder.start();
进程正在启动,但当我们试图将它与 jconsole
通过远程,它不能连接... ...和连接失败的消息。
Remote connection URL: service:jmx:rmi:///jndi/rmi://A.B.C.D:9875/jmxrmi
我们已经试过了:
-Djava.rmi.server.hostname=A.B.C.D
和 -Dcom.sun.management.jmxremote.local.only=false
ProcessBuilder.getEnv()
并添加了我们的环境属性。当我们通过命令提示符运行同一个程序时。
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9875 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -cp C:\jobs\abc.jar org.springframework.batch.core.launch.support.CommandLineJobRunner
它正在运行并且能够连接到 jmx
通过远程与上述相同的URL。
任何建议workaround都将是欢迎的!!!。
每个 -D
选项需要成为 ProcessBuilder
:
ProcessBuilder pb = new ProcessBuilder("java",
"-Dcom.sun.management.jmxremote",
"-Djava.rmi.server.hostname=A.B.C.D",
// etc. etc.
"-cp", jobArtifact.getAbsolutePath(),
"org.springframework.batch.core.launch.support.CommandLineJobRunner");
final Process process = processBuilder.start();
你现在的代码,把所有的代码连成一个参数,基本上是在设置 一个 名为 "com.sun.management.jmxremote -Djava.rmi.server.hostname"
价值 "A.B.C.D -Dcom.sun.management.jmxremote.port=9875 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false "
(包括尾部空间)。