如何通过Java代码连接JBoss 7.1.1的远程-jmx?

4

我有一个JBoss 7.1.1服务器,想要编写JMX客户端。据我所知,JBoss 7.1.1不使用典型的基于RMI的JMX,而是在本机管理上添加了一个远程-JMX层。我正在使用以下代码:

JMXServiceURL address = new JMXServiceURL("service:jmx:remoting-jmx://localhost:9999");

Map env = JMXConnectorConfig.getEnvironment(paramtbl);

JMXConnector connector = JMXConnectorFactory.connect(address, env);

但它会出现以下异常:
java.net.MalformedURLException: Unsupported protocol: remoting-jmx

我谷歌搜索了一下,下面的帖子看起来与此相关: https://community.jboss.org/thread/204653?tstart=0 它建议将jboss的库添加到我的类路径中。我也尝试了这样做,但仍然遇到相同的异常。
6个回答

10

当尝试获取 JmxServiceUrl 时,我遇到了相同的异常。确保在您的 standalone.xml 文件中包含以下内容:

<subsystem xmlns="urn:jboss:domain:jmx:1.1"> <show-model value="true"/> <remoting-connector use-management-endpoint="true" /> </subsystem>

并且您应该将名为jboss-client.jar 的jar文件包含在项目类路径中,它可以在JBOSS_DIRECTORY/bin/client中找到。实际上,JMX客户端必须在其类路径中包含那个jar。

这个提示为我解决了问题.. 希望对您有所帮助


我的问题仅仅是因为 jboss-client.jar。我的类路径中有重复的条目,其中第一个来自早期的 jboss 版本。 - Naman

1

我尝试在JBoss AS7上使用Arquillian测试做同样的事情,最终不得不使用:

import org.jboss.remotingjmx.RemotingConnectorProvider;

RemotingConnectorProvider s = new RemotingConnectorProvider();
JMXConnector connector = s.newJMXConnector(url, credentials);
connector.connect();

无法使用"module name="org.jboss.remoting-jmx" services="import""

也适用于

environment.put("jmx.remote.protocol.provider.pkgs", "org.jboss.remotingjmx");
JMXConnector connector = JMXConnectorFactory.connect(url, environment);
connector.connect();

1

我使用这段代码连接到远程服务器上的JBoss

ModelControllerClient client = null;
try {
 client = createClient(InetAddress.getByName("172.16.73.12"), 9999,
     "admin", "pass", "ManagementRealm");
    } 
catch (UnknownHostException e) {
 e.printStackTrace();
}

createClient是我编写的一个方法 -

private ModelControllerClient createClient(final InetAddress host,
  final int port, final String username, final String password,
  final String securityRealmName) {

 final CallbackHandler callbackHandler = new CallbackHandler() {

  public void handle(Callback[] callbacks) throws IOException,
    UnsupportedCallbackException {
   for (Callback current : callbacks) {
    if (current instanceof NameCallback) {
     NameCallback ncb = (NameCallback) current;
     ncb.setName(username);
    } else if (current instanceof PasswordCallback) {
     PasswordCallback pcb = (PasswordCallback) current;
     pcb.setPassword(password.toCharArray());
    } else if (current instanceof RealmCallback) {
     RealmCallback rcb = (RealmCallback) current;
     rcb.setText(rcb.getDefaultText());
    } else {
     throw new UnsupportedCallbackException(current);
    }
   }
  }
 };
 return ModelControllerClient.Factory
   .create(host, port, callbackHandler);
}

如果您想了解如何读取从服务器获取的数据,或者想了解使用Java/Google可视化API(每隔10秒在图表中显示统计信息)的完整项目,请参考本教程 -

http://javacodingtutorial.blogspot.com/2014/05/reading-jboss-memory-usage-using-java.html


0

看起来在 JMX 连接的运行时中没有 "jboss-client.jar",所以请确保已将 "jboss-client.jar" 添加到类路径中。 同时,您正在使用已弃用的协议 "remoting-jmx" 而不是 "remote"。

即,"service:jmx:remote://localhost:9999"

希望能对您有所帮助。


0
将以下内容添加到您的 jboss-deployment-structure 中。

   <dependencies>
         <module name="org.jboss.remoting3.remoting-jmx" services="import"/>
   </dependencies>


0

在 standalone.xml 文件中添加以下条目以激活 JMX 远程子系统

<subsystem xmlns="urn:jboss:domain:ee:1.1">
  <!-- Activate JMX remoting -->
  <global-modules>
    <module name="org.jboss.remoting-jmx" slot="main"/>
  </global-modules>
  ...
</subsystem>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接