1. 程式人生 > >jmx獲取jboss配置資訊

jmx獲取jboss配置資訊

首先把jar包下載下來(jboss-4.2.3.GA)

http://download.csdn.net/detail/u010792467/7753867

把jar包放在lib下面,在eclipse中新增以下程式碼

Java類

publicstaticvoid main(String[] args)throws Exception {

//Get RMIAdaptor Object

Properties pro =new Properties();

pro.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"

);

pro.setProperty("java.naming.provider.url","jnp://localhost:1099");

pro.setProperty("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");

InitialContext ic =new InitialContext(pro);

RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/rmi/RMIAdaptor");

// Get the MBeanInfo for the JNDIView MBean

ObjectName name =new ObjectName("jboss:service=JNDIView");

MBeanInfo info = server.getMBeanInfo(name);

System.out.println("JNDIView Class: " + info.getClassName());

MBeanOperationInfo[] opInfo = info.getOperations();

System.out.println("JNDIView Operations: ");

for (int o = 0; o < opInfo.length

; o++){

MBeanOperationInfo op = opInfo[o];

String returnType = op.getReturnType();

String opName = op.getName();

System.out.print(" + " + returnType + " " + opName +"(");

MBeanParameterInfo[] params = op.getSignature();

for (int p = 0; p < params.length; p++) {

MBeanParameterInfo paramInfo = params[p];

String pname = paramInfo.getName();

String type = paramInfo.getType();

if (pname.equals(type))

System.out.print(type);

else

System.out.print(type +" " + name);

if (p < params.length - 1)

System.out.print("");

}

System.out.println(")");

}

//Get all MBeans

Set mbSet = server.queryMBeans(null,null);//

for (Iterator it = mbSet.iterator(); it.hasNext();) {

ObjectInstance oi = (ObjectInstance) it.next();

System.out.println(oi.getObjectName());

}

}

下面是程式碼和控制檯輸出的資訊。

作者:儱劍阿攵
轉載請註明連結:http://blog.csdn.net/awenluck/article/details/38560429