我想将Java客户端与JBoss 6.4.0 EAP一起使用。我测试了这段代码:
public void testConnection() throws Exception { System.out.println("Starting lookup ..."); ObjectName mBeanName = new ObjectName("java.lang:type=Runtime"); String attributeName = "StartTime"; String host = "104.233.103.41"; int port = 9999; // management-native port String urlString = System.getProperty("jmx.service.url", "service:jmx:remoting-jmx://" + host + ":" + port); JMXServiceURL serviceURL = new JMXServiceURL(urlString); JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null); MBeanServerConnection connection = jmxConnector.getMBeanServerConnection(); Object attrVal = connection.getAttribute(mBeanName, attributeName); System.out.println("Value via JMX: " + new Date((Long) attrVal)); }
我的项目基于Maven,因此我添加了以下依赖项:
org.jboss.as jboss-as-ejb-client-bom pom org.jboss.as jboss-as-jms-client-bom pom
但是我在运行代码时收到此错误:
java.net.MalformedURLException: Unsupported protocol: remoting-jmx at javax.management.remote.JMXConnectorFactory.newJMXConnector(JMXConnectorFactory.java:359) at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:269)
在EAP-6.4.0 / bin / client中,我找到了以下描述:
jboss-client.jar是JBoss EAP 6的组合客户端jar,可在非Maven环境中使用。此jar只能与独立客户端一起使用,而不能与部署到JBoss EAP 6实例的部署一起使用。
此jar包含远程JMS和EJB使用所需的类,并且由以下阴影工件组成:
org.jboss.spec.javax.jms:jboss-jms-api_1.1_spec org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec org.jboss:jboss-ejb-client org.jboss:jboss-remote-naming org.jboss.logging:jboss-logging org.jboss.marshalling:jboss-marshalling org.jboss.marshalling:jboss-marshalling-river org.jboss.remoting3:jboss-remoting org.jboss.remoting3:remoting-jmx org.jboss.sasl:jboss-sasl org.jboss.xnio:xnio-api org.jboss.xnio:xnio-nio org.jboss.netty:netty org.hornetq:hornetq-core-client org.hornetq:hornetq-jms-client
Maven用户不应使用此jar,而应使用以下BOM依赖项
org.jboss.as jboss-as-ejb-client-bom pom org.jboss.as jboss-as-jms-client-bom pom
这是因为将maven与带阴影的jar一起使用极有可能导致类版本冲突,这就是为什么我们不将该jar发布到maven存储库的原因。
但是我又得到这个错误。你能提出一些解决方案吗?
向remoting-jmx协议添加依赖项,即org.jboss.remoting3:remoting-jmx
按照https://developer.jboss.org/thread/199914?tstart=0
org.jboss.remoting3 remoting-jmx 1.0.1.Final
完整且有效的POM:
4.0.0 test test 0.0.1-SNAPSHOT 1.8 1.8 org.jboss.as jboss-as-ejb-client-bom pom 7.2.0.Final org.jboss.as jboss-as-jms-client-bom pom 7.2.0.Final org.jboss.remoting3 remoting-jmx 1.0.1.Final junit junit 4.12 test
使用在本地主机上运行的JBoss服务器运行Maven构建:
------------------------------------------------------- T E S T S ------------------------------------------------------- Running test.ATest Starting lookup ... Dec 16, 2015 6:25:50 PM org.xnio.XnioINFO: XNIO Version 3.0.7.GA Dec 16, 2015 6:25:50 PM org.xnio.nio.NioXnio INFO: XNIO NIO Implementation Version 3.0.7.GA Dec 16, 2015 6:25:50 PM org.jboss.remoting3.EndpointImpl INFO: JBoss Remoting version 3.2.14.GA Value via JMX: Wed Dec 16 18:14:05 CST 2015 Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.89 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0