Skip to content

Instantly share code, notes, and snippets.

@nobeans
Created November 12, 2012 15:40
Show Gist options
  • Save nobeans/4060046 to your computer and use it in GitHub Desktop.
Save nobeans/4060046 to your computer and use it in GitHub Desktop.
Access to local JVM's JVM servers without port
//
// Access to local JVM's JVM servers without port
// http://stackoverflow.com/questions/5552960/how-to-connect-to-a-java-program-on-localhost-jvm-using-jmx
//
import com.sun.tools.attach.*
import javax.management.remote.*
import javax.management.*
VirtualMachine.list().each { desc ->
println "-"*50
println "[${desc.id()}] - ${desc.displayName()}"
println ""
VirtualMachine vm = VirtualMachine.attach(desc)
def connectorAddress = vm.agentProperties.getProperty("com.sun.management.jmxremote.localConnectorAddress")
if (!connectorAddress) return
def url = new JMXServiceURL(connectorAddress)
JMXConnector connector = JMXConnectorFactory.connect(url)
try {
connector.MBeanServerConnection.queryNames(null, null).each {
println " $it"
}
} finally {
connector.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment