Glassfish 2.1 EJB 3.0 Exposing local EJB to other applications running in the same domain/jvm

前端 未结 1 1081
傲寒
傲寒 2020-12-19 07:17

I have an existing project that I am in need of configuring different. This needs to happen without major code changes. I am actually hoping I could somehow do this only wit

相关标签:
1条回答
  • 2020-12-19 07:59

    The link @Peter gave you almost solves your problem. (link)

    One trick which needs to be done to solve @Xavier's problem is to provide common.jar to both ears in the same version (loaded by the same class loader). If you do it, the class cast exception will not be thrown and you will be able to use the ejb with local interface.

    To do it you need to put common.jar into glassfish/domains/domain1/lib folder (substitute domain1 with you domain name). This way this jar will be loaded by a Glassfish's shared class loader.

    I made a quick test with Eclipse and Glassfish 3 with following structure:

    package com.example;
    
    JarShared
     - @Local class Server
    
    EarServer
     - EjbServer
        - @Stateless class ServerBean implements Server
    
    EarClient
     - EjbClient
        - @Stateless @LocalBean class ClientBean
    

    Lookup from ClientBean:

    InitialContext ic = new InitialContext();
    Server server = (Server) ic.
        lookup("java:global/EarServer/EjbServer/ServerBean!com.example.Server");
    

    I did not get ClassCastException and I could call sample method from ServerBean.

    Important notes:

    • both EarServer and EarClient should not contain JarShared in lib folder, they should reuse the one which is in domains lib folder
    • remember to restart Glassfish after adding JarShared to it.
    • to make both ejb projects compile you must add JarShared to their build paths, but nothing more

    If you have questions, post a comment.

    0 讨论(0)
提交回复
热议问题