title: Local JMX invokation fails with ClassCastException
body: <p>I'm trying to invoke JMX service locally using the following simple code below. It works fine with JConsole, however under command line it throws exception on the last line of the pasted code. </p>
  
  <pre><code>    String serviceURL = "service:jmx:rmi:///jndi/rmi://localhost:" + configuration.getJmxPort();
      String[] credentials = new String[]{configuration.getUsername(), configuration.getPassword()};
      Map&lt;String, String[]&gt; attributes = new HashMap&lt;String, String[]&gt;();
      attributes.put("jmx.remote.credentials", credentials);
  
      JMXServiceURL jmxUrl = new JMXServiceURL(serviceURL);
      jmxCon = JMXConnectorFactory.connect(jmxUrl, attributes);
  </code></pre>
  
  <p>The stack trace looks like this:</p>
  
  <pre><code>java.lang.ClassCastException: com.sun.jndi.rmi.registry.RegistryContext cannot be cast to javax.management.remote.rmi.RMIServer
      at javax.management.remote.rmi.RMIConnector.narrowJRMPServer(RMIConnector.java:1897)
      at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1892)
      at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1856)
      at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:257)
      at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:248)
      at com.aaa.aaa.aaa.jmx.AaaJmxClient.main(AaaJmxClient.java:36)
  </code></pre>