Discussions

General J2EE: common ejb deployment for multiple apps

  1. common ejb deployment for multiple apps (1 messages)

    This seems to be one of the classic deployment-packaging questions,
    but there's more about it, since it addresses on of the inherent
    J2EE drawbacks -- a high degree of freedom given by the specification
    leaves some spots unattended.
    To get to the point:

    The problem to be solved can be described in short as:
    how do I package the same EJBs in (quite a lot of) applications?

    Imagine you have, let's take any number, 50 web applications,
    running on one AS. They all are totally different except for
    some utility classes and ejbs. Besides this, I'm talking about
    living code, so there's no such thing as: all 50 applications,
    the utility classes and ejbs are written once and that's it.
    Anything could be changed at any time and has to be redeployed
    on a running server.

    I think it's quite a standard to use ear files since they give
    a good degree of flexibility. In this discussion, I leave out
    the resource adapter and client application issues. So I'm talking
    only about web applications, utiltity classes, and ejbs.

    The goals should be:
    a) not to have anything in the AS classpath (well, that's clear I think)
    b) being able to deploy each application individually without
       having any impact on the other applications
    c) avoid duplicate code (especially ejbs, see below) in the ear files

    So the basic options are clear: independent applications require
    a full loaded set of files (web application, utility, ejb). If your
    server -- hard- and software -- can handle that (after doing some
    performance tests), this seems to be a good option.
    However, there's still the problem with the ejbs in case that they
    are (at this point) doing exactly the same for all applications.
    (Let's quit the discussion about why they are doing the same right
    now and maybe they won't do that in the future)

    If the same ejb is deployed in multiple ear files, the following
    problems arise:
    1) the ejb has to be deployed with a different lookup name for each
    ear file and your applications have to be set up the way that they
    know that name (deployment time knowledge somehow coded in your
    application)
    2) how does the ejb (which is designed to do the same for all applications)
    guarantee to do what a single ejb usually guarantees (transactions, security, ...)

    Is there any elegant way to have each application in a separate ear file
    with its own set of utility classes, but having the ejbs (common ejbs for
    all applications)in some place such that they are deployed only once?

    Holger Wiechert





  2. Hi,

    I have no idea what app server you are using, but on my favorite app server, the answer to your last question, "Is there any elegant....?", is yes.

    <quote>
    If the same ejb is deployed in multiple ear files, the following
    problems arise:
    1) the ejb has to be deployed with a different lookup name for each
    ear file and your applications have to be set up the way that they
    know that name (deployment time knowledge somehow coded in your
    application)
    </quote>

    EJB References allow you to refer to the 'logical' name of a bean in the code by specifying the mapping between this logical name and the actual jndi name of the bean in the deployment descriptor. See Chapter 20 of the EJB 2.0 Spec.

    <quote>
    2) how does the ejb (which is designed to do the same for all applications)
    guarantee to do what a single ejb usually guarantees (transactions, security, ...)
    </quote>

    The elements of the deployment descriptor define the container services, like transactions, security, etc. What is the difference if you use an ejb with one app or many? That is opaque to the caller.

    The solution to your problem is really quite simple. Put all of the common ejb code, which includes the utilities, helpers, whatever, into a common set of ejb's that are deployed once in their own ear/jar file. Then, look them up from the business ejb code in the other 50 ear/jar files using the <ejb-ref> deployment element that refers to the utility ejb.

    <quote>
    Is there any elegant way to have each application in a separate ear file
    with its own set of utility classes, but having the ejbs (common ejbs for
    all applications)in some place such that they are deployed only once?
    </quote>

    Yes, see above. ;-)

    Bill