src/main/java/org/lazydog/mbean/utility/RemoteMBeanInvocationHandler.java
private static JMXConnector connect(String host, String port, String login, String password) throws IOException {

        // Set the service URL.
        JMXServiceURL serviceUrl = new JMXServiceURL(
                new StringBuffer()
                    .append("service:jmx:rmi://")
                    .append(host)
                    .append(":")
                    .append(port)
                    .append("/jndi/rmi://")
                    .append(host)
                    .append(":")
                    .append(port)
                    .append("/jmxrmi")
                    .toString());

        // Set the service environment.
        Map<String,Object> serviceEnv = new HashMap<String,Object>();
        serviceEnv.put("jmx.remote.credentials", new String[]{login, password});

        // Connect to the JMX service.
        return JMXConnectorFactory.connect(serviceUrl, serviceEnv);
    }
private static JMXConnector connect(String host, String port, String login, String password) throws IOException {

        // Set the service URL.
        JMXServiceURL serviceUrl = new JMXServiceURL(
                new StringBuffer()
                    .append("service:jmx:rmi://")
                    .append(host)
                    .append(":")
                    .append(port)
                    .append("/jndi/rmi://")
                    .append(host)
                    .append(":")
                    .append(port)
                    .append("/jmxrmi")
                    .toString());

        // Set the service environment.
        Map<String,Object> serviceEnv = new HashMap<String,Object>();
        serviceEnv.put("jmx.remote.credentials", new String[]{login, password});

        // Connect to the JMX service.
        return JMXConnectorFactory.connect(serviceUrl, serviceEnv);
    }
Connect to the JMX service.

@param  host      the host.
@param  port      the port.
@param  login     the login.
@param  password  the password.

@return  the JMX connector.

@throws  IOException  if unable to connect to the JMX service.