title: What is wrong with this Java code for a RMI JMX connection?
body: <p>What is wrong with this Java code for a RMI JMX connection?   I am clearly not trying to connect to localhost but the error implies that I am.   On the remote server, I enabled JMX options on port 1099 (no authentication).</p>
  
  <p>Here is my groovy script:</p>
  
  <pre><code>import javax.management.remote.*;    
  JMXServiceURL u = 
   new JMXServiceURL("service:jmx:rmi://10.222.244.185:9999/jndi/rmi://10.222.244.185:1099/jmxrmi");    
  JMXConnector c = JMXConnectorFactory.connect(u);
  </code></pre>
  
  <p>And here is the error I get:</p>
  
  <pre><code>C:\Temp&gt;groovy jmx.gv
  Caught: java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Conn
  ection refused to host: 10.222.244.185; nested exception is:
          java.net.ConnectException: Connection refused: connect]
  java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection r
  efused to host: 10.222.244.185; nested exception is:
          java.net.ConnectException: Connection refused: connect]
          at jmx.run(jmx.gv:5)
  Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: 10.222.244.185; nested except
  ion is:
          java.net.ConnectException: Connection refused: connect]
          at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:101)
          at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:185)
          ... 1 more
  Caused by: java.rmi.ConnectException: Connection refused to host: 10.222.244.185; nested exception is:
          java.net.ConnectException: Connection refused: connect
          at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:97)
          ... 2 more
  Caused by: java.net.ConnectException: Connection refused: connect
          ... 3 more
  </code></pre>