MalformedURLException Unsupported protocol remoting-jmx when JMX client tries to connect to JBoss EAP 6 MBean Server
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6
- 7
Issue
- Getting Unsupported protocol when trying to connect to JMX using
remoting-jmxprotocol from a client application running in JBoss EAP 6.0.x. The exception is:
03:09:24,429 ERROR java.net.MalformedURLException: Unsupported protocol: remoting-jmx
03:09:24,430 ERROR at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:327)
03:09:24,430 ERROR at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:247)
03:09:24,430 ERROR at com.jboss.examples.ejb.HelloBean.printMBeanCount(PrintMBeansSingleton.java:57)
...
- The client code connection is:
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
@Stateless
public class HelloBean {
public int printMBeanCount() throws Exception {
String host = "localhost";
int port = 9999; // management-native port
String urlString = System.getProperty("jmx.service.url","service:jmx:remoting-jmx://" + host + ":" + port);
JMXConnector jmxConnector = null;
try {
JMXServiceURL serviceURL = new JMXServiceURL(urlString);
JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
return connection.getMBeanCount();
} finally {
if(jmxConnector != null) jmxConnector.close();
}
}
Resolution
For a standalone application not running in JBoss EAP 6.x
Put the $JBOSS_HOME/bin/client/jboss-client.jar into your classpath
For An Application running in JBoss EAP 6.x:
- Add a JBoss Modules dependency on
org.jboss.remoting3.remoting-jmx with services="import" - Note: in JBoss EAP 6.1 and later, the module
org.jboss.remoting3.remoting-jmxis an alias fororg.jboss.remoting-jmx, so either can be used.
Using
jboss-deployment-structure.xml
- The
jboss-deployment-structure.xmlgoes in the top level deployment only, if your client application top level deployment is a war, the xml goes inWEB-INF, if it is any other type, it goes inMETA-INF
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.jboss.remoting3.remoting-jmx" services="import" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
Note: The export="true" you should add if your top level deployment is an ear and you want to expose the remoting-jmx classes to your sub deployments.
Using MANIFEST.MF Dependencies
- Add the dependency to the
MANIFEST.MFof the client application
Dependencies: org.jboss.remoting3.remoting-jmx services
Using jboss-client.jar
- Client applications can package the
$JBOSS_HOME/bin/client/jboss-client.jarinside of them, though this duplicates classes already available in the container, so it saves space to just add module dependencies.
Maven dependency for standalone client EAP 6.2.x and later
- The following dependencies must exist in pom.xml file:
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-jms-client-bom</artifactId>
<version>7.3.1.Final-redhat-4</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.remotingjmx</groupId>
<artifactId>remoting-jmx</artifactId>
<version>1.1.2.Final-redhat-1</version>
</dependency>
</dependencies>
Related Articles
Can I use Spring JMX connectors with JBoss EAP?
Root Cause
-
org.jboss.remoting3.remoting-jmxregisters theremoting-jmxprotocol in EAP 6.0.x andorg.jboss.remoting-jmxregisters theremoting-jmxprotocol in EAP 6.1.x and EAP 6.2.x. -
services="import"is required because by defaultMETA-INF/servicesare not imported/visible, and the services are needed for:javax.management.remote.JMXConnectorProvider. -
This
javax.management.remote.JMXConnectorProvideris in theremoting-jmxmodule which can be used when the client is running in JBoss EAP 6 and is also injboss-client.jarfor standalone java applications to use.
$JBOSS_HOME/modules/org/jboss/remoting3/remoting-jmx/main/remoting-jmx-1.0.4.Final-redhat-1.jar/META-INF/services/javax.management.remote.JMXConnectorProvider
$JBOSS_HOME/bin/client/jboss-client.jar/META-INF/services/javax.management.remote.JMXConnectorProvider
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.