Cannot attach to VM via VirtualMachine.attach() API
Hi,
In my plugin, I have written a custom ProgramRunner and the user can create a run configuration and start my custom program as a separate JVM. I know the process ID of this newly created JVM and hence I use below code to obtain the connector address of the JVM, so I could connect to it via JMX
private static final String LOCAL_CONNECTOR_ADDRESS = "com.sun.management.jmxremote.localConnectorAddress";
vm = VirtualMachine.attach(String.valueOf(jvmId));
connectorAddress = vm.getAgentProperties().getProperty(LOCAL_CONNECTOR_ADDRESS);
if (connectorAddress == null) {
String agent = vm.getSystemProperties().getProperty("java.home") +
File.separator + "lib" + File.separator + "management-agent.jar";
vm.loadAgent(agent);
connectorAddress = vm.getAgentProperties().getProperty(LOCAL_CONNECTOR_ADDRESS);
}
vm.detach();
But this code does not work in IU-2016.1.2. Basically, the code after
VirtualMachine.attach()
method does not get executed and there is no exceptions either. But it works on IU-15.0. I'm wondering whether this breaks due to the security fix done as mentioned in below blog post.
Anyone knows what to do about this?
Please sign in to leave a comment.
Hey @..., how can the process id of the started JVM be retrieved?