一些其他资料
2012/2/3补充:
import java.util.Properties; import javax.management.JMX; import javax.management.MBeanServerConnection; import javax.management.ObjectName; import javax.naming.InitialContext; import com.test.bean.TestSingletonRemoteIfc; import com.test.mbean.HelloWorldMBean;
/** * */ public class Test { /** * @param args */ public static void main(String[] args) { while(true) { try { //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);
// find a singleton bean to test TestSingletonRemoteIfc singleton = (TestSingletonRemoteIfc)ic.lookup("TestSarEar/TestSingletonBean/remote-com.test.bean.TestSingletonRemoteIfc"); System.out.println("EJB1: " + singleton.getValue()); System.out.println("EJB2: " + singleton.getSuffix());
// find MBean //RMIAdaptor server = (RMIAdaptor) ic.lookup("jmx/rmi/RMIAdaptor"); MBeanServerConnection connection = (MBeanServerConnection) ic .lookup("jmx/invoker/RMIAdaptor"); HelloWorldMBean myMBean = (HelloWorldMBean) JMX.newMBeanProxy( connection, new ObjectName("com.test.mbean:service=HelloWorld"), HelloWorldMBean.class); System.out.println("JNDI: " + myMBean.printGreeting()); Thread.sleep(1000); } catch (Exception e) { System.out.println("Damn!!"); e.printStackTrace(); } } } }