Tomcat6遠(yuǎn)程調(diào)用GlassFishV2的sessionbean

字號(hào):

Tomcat6遠(yuǎn)程調(diào)用GlassFish V2的session bean
    GlassFish V2 是一個(gè)比較完整的ejb3服務(wù)器,性能也有了很大的提高,因此最近試用了一下,并通過Tomcat進(jìn)行了分布式調(diào)用。
    Session Bean: com.test.session.TestSessionBean, TestSessionRemote
    web項(xiàng)目: test_web
    要作以下處理:
    1 Tomcat的test_web/WEB-INF/lib加載GlassFish的Client包,可以通過https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html查看官方的說明,我的類包中含有:
    C:\\Java\\glassfish-v2\\lib\\appserv-ws.jar;C:\\Java\\glassfish-v2\\lib\\install\\applications\\jmsra\\imqjmsra.jar;C:\\Java\\glassfish-v2\\lib\\install\\applications\\jmsra\\imqjmx.jar;C:\\Java\\glassfish-v2\\lib\\javaee.jar;C:\\Java\\glassfish-v2\\lib\\appserv-ee.jar;C:\\Java\\glassfish-v2\\lib\\appserv-ext.jar;C:\\Java\\glassfish-v2\\lib\\appserv-deployment-client.jar;C:\\Java\\glassfish-v2\\lib\\jmxremote_optional.jar;C:\\Java\\glassfish-v2\\lib\\appserv-rt_ja.jar
    2 如果沒在classpath中設(shè)置ant,則還要在%Tomcat%/lib下加入ant.jar,ant-launcher.jar.
    3 Context的設(shè)置
    Properties props = new Properties();
    props.setProperty("java.naming.factory.initial",
    "com.sun.enterprise.naming.SerialInitContextFactory");
    props.setProperty("java.naming.factory.url.pkgs",
    "com.sun.enterprise.naming");
    props.setProperty("java.naming.factory.state",
    "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
    // optional. Defaults to localhost. Only needed if web server is running
    // on a different host than the appserver
    props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
    // optional. Defaults to 3700. Only needed if target orb port is not 3700.
    props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
    InitialContext ic = new InitialContext(props);
    4 在lookup時(shí),要用Bean的完整類名:com.test.TestSessionRemote
    5 日志輸出
    java.util.logging.Logger.getLogger(getClass().getName()).log(java.util.logging.Level.SEVERE, "exception caught", ne);
    OK。Tomcat與GlassFish的EJB3就可以合作了。