Tomcat6远程调用GlassFish V2的session bean

阅读更多
Tomcat6远程调用GlassFish V2的session bean
GlassFish V2 是一个比较完整的ejb3服务器,性能也有了很大的提高,因此最近试用了一下,并通过Tomcat进行了分布式调用。
Session Bean: com.test.session.TestSessionBean, TestSessionRemote
web项目: 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中设置ant,则还要在%Tomcat%/lib下加入ant.jar,ant-launcher.jar.
3 Context的设置

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时,要用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就可以合作了。

你可能感兴趣的:(Bean,Glassfish,Java,Tomcat,Ant)