title: Failed to connect to JMX while started to use the JMX authentication on Linux
body: <p>My JMX client failed to connect to JMX server while I have started to use the JMX authentication.
  I use Java 8 and Centos6.</p>
  
  <p>I have configured the following settings:</p>
  
  <pre><code>JAVA_OPTS="${JAVA_OPTS} -Dcom.sun.management.jmxremote.authenticate=true  -Dcom.sun.management.jmxremote.password.file=&lt;path to password file&gt; -Dcom.sun.management.jmxremote.access.file=&lt;path to access file&gt;"
  </code></pre>
  
  <p>Unfortunately my JMX client failed to connect to JMX server with the following exception:</p>
  
  <pre><code>java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
          java.net.ConnectException: Connection refused]
          at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:369)
          at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270)
          at org.apache.catalina.ant.jmx.JMXAccessorTask.createJMXConnection(JMXAccessorTask.java:384)
          at org.apache.catalina.ant.jmx.JMXAccessorTask.accessJMXConnection(JMXAccessorTask.java:439)
          at org.apache.catalina.ant.jmx.JMXAccessorTask.getJMXConnection(JMXAccessorTask.java:477)
          at org.apache.catalina.ant.jmx.JMXAccessorTask.execute(JMXAccessorTask.java:345)
          at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
          at org.apache.tools.ant.Task.perform(Task.java:348)
          at org.apache.tools.ant.Target.execute(Target.java:435)
          at org.apache.tools.ant.Target.performTasks(Target.java:456)
          at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
          at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
          at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
          at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
          at org.apache.tools.ant.Main.runBuild(Main.java:851)
          at org.apache.tools.ant.Main.startAnt(Main.java:235)
          at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
          at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
  Caused by: javax.naming.ServiceUnavailableException [Root exception is java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
          java.net.ConnectException: Connection refused]
          at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:122)
          at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:205)
          at javax.naming.InitialContext.lookup(InitialContext.java:417)
          at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1957)
          at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1924)
          at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287)
          ... 22 more
  Caused by: java.rmi.ConnectException: Connection refused to host: localhost; nested exception is:
          java.net.ConnectException: Connection refused
          at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:619)
          at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:216)
          at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:202)
          at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:342)
          at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
          at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:118)
          ... 27 more
  Caused by: java.net.ConnectException: Connection refused
          at java.net.PlainSocketImpl.socketConnect(Native Method)
          at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
          at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
          at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
          at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
          at java.net.Socket.connect(Socket.java:589)
          at java.net.Socket.connect(Socket.java:538)
          at java.net.Socket.&lt;init&gt;(Socket.java:434)
          at java.net.Socket.&lt;init&gt;(Socket.java:211)
          at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:40)
          at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:148)
          at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:613)
          ... 32 more
  </code></pre>