We are getting problem in connecting through jmx via remote.we run a job through ProcessBuilder by program
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();
Process is being started but when we try to connect it with jconsole
via remote it's not connecting... and connection failed message is coming:
Remote connection URL: service:jmx:rmi:///jndi/rmi://A.B.C.D:9875/jmxrmi
What we have tried:
-Djava.rmi.server.hostname=A.B.C.D
and-Dcom.sun.management.jmxremote.local.only=false
ProcessBuilder.getEnv()
and added our environment properties.When we are running the same program via command prompt:
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
it is running and able to connect with jmx
via remote with the same URL mentioned above.
Any suggestions/workaround would be welcome!!!
Each -D
option needs to be a separate parameter to the 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();
Your current code, with all of them concatenated together into one parameter, is essentially setting one property named "com.sun.management.jmxremote -Djava.rmi.server.hostname"
to the value "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 "
(including the trailing space).