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

佐手、 提交于 2019-11-29 10:33:19
MeTTeO

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!