5 Replies Latest reply on Aug 23, 2004 3:19 AM by alessandro_rizzi

    2 J2EE application with the same EJB

    alessandro_rizzi Newbie

      I would like to have 2 J2EE applications containg the same EJB, is this possible?
      I have JBoss 3.2.3 and the situation should be this:
      I should have 2 folders like this:
      ..\jboss-3.2.3\server\default\deploy\myApp1
      ..\jboss-3.2.3\server\default\deploy\myApp2

      Both folder myApp1 & myApp2 contains (for example) jarA.jar which contains the same EJB's.
      The pourpose of the 2 folder is to have the same application in 2 different versions.

      If I made a configuration like this, I get an error:
      ERROR [EJBModule] Could not create JSR-77 EJBModule: jarA.jar
      javax.management.InstanceAlreadyExistsException: jboss.management.local:J2EEApplication=null,J2EEServer=Local,j2eeType=EJBModule,name=jarA.jar registered.

      Can anybody help me?
      Maybe I've to set something to NOT have "J2EEApplication=null"?
      Or this kind of configuration (which works well on Orion) is not possible?
      Regards
      Alessandro Rizzi

        • 1. Re: 2 J2EE application with the same EJB
          wtff Newbie

          yes this is possible.

          First of all, if you just deploy ejb-jars by placing them somewhere below the deploy directory, their classes will be loaded into the same loader repository.
          So lets first start with the simple case of having an ejb which you want to deploy two times, lets say with different configuration settings. You can do this, but you have to make sure to use two different ejb-names and two different JNDI paths.

          If the bean should also be able to exist in two different versions, you have to ensure that they are loaded into different classloader repositories. In order to achieve this, you have to put them into two different ear archives. Within the jboss-app.xml file in the META-INF directory of the ear archive you need to specify a separate loader repository for each ear:


          <?xml version='1.0' encoding='UTF-8' ?>
          
          <!DOCTYPE jboss-app
           PUBLIC "-//JBoss//DTD J2EE Application 1.3V2//EN"
           "http://www.jboss.org/j2ee/dtd/jboss-app_3_2.dtd">
          
          <jboss-app>
          
           <loader-repository>jmx-domain-name:loader=application-ONE</loader-repository>
          
          </jboss-app>
          





          • 2. Re: 2 J2EE application with the same EJB
            alessandro_rizzi Newbie

             

            "wtff" wrote:
            yes this is possible.

            First of all, if you just deploy ejb-jars by placing them somewhere below the deploy directory, their classes will be loaded into the same loader repository.
            So lets first start with the simple case of having an ejb which you want to deploy two times, lets say with different configuration settings. You can do this, but you have to make sure to use two different ejb-names and two different JNDI paths.


            How can I have two different ejb-names? Modifing the ejb-jar.xml of each one? I cannot do that, since in this way I should also modify the client call.
            I'd like to have the same EJB name, but a differenti J2EE application name. In Orion this is possible, I can deploy the same Jar in 2 different application, and the only thing to do on the client is changing the J2EE application name in the lookup.

            "wtff" wrote:

            If the bean should also be able to exist in two different versions, you have to ensure that they are loaded into different classloader repositories. In order to achieve this, you have to put them into two different ear archives. Within the jboss-app.xml file in the META-INF directory of the ear archive you need to specify a separate loader repository for each ear:


            
            <?xml version='1.0' encoding='UTF-8' ?>
            
            <!DOCTYPE jboss-app
             PUBLIC "-//JBoss//DTD J2EE Application 1.3V2//EN"
             "http://www.jboss.org/j2ee/dtd/jboss-app_3_2.dtd">
            
            <jboss-app>
            
             <loader-repository>jmx-domain-name:loader=application-ONE</loader-repository>
            
            </jboss-app>
            




            Thanks for your help, I'll try to make the 2 EAR's, but if you can ask to the above question, I'll be very thankful.
            Reagards
            Alessandro Rizzi

            • 3. Re: 2 J2EE application with the same EJB
              wtff Newbie

              yes, that's right. I'm sorry. The ejb-name can be the same, since it only needs to be unique within the scope of a jar file. So you just need to ensure that you don't accidentially deploy both ejbs with the same jndi-path.

              If you do not specify a jndi path explicitely within the jboss.xml descriptor, the jndi-path will be constructed on the basis of the ejb-name and then the two ejbs won't deploy correctly because of the same jndi-path.

              When setting the jndi-path manually, you might want to pay special attention to the difference between the tag called jndi-name and local-jndi-name which applies to the local home interface. If you use the wrong tag, jboss will use the ejb-name to construct the jndi-name of your bean and your deployment will fail although you think you had specified the jndi-path...

              • 4. Re: 2 J2EE application with the same EJB
                wtff Newbie

                P.S:

                BTW, I do not have any experience with EJB clients. If you follow the above instructions, your ejbs will deploy correctly and will be able to coexist. I'm using this kind of configuration to isolate applications from one another.

                If you have one single client which has to invoke both bean versions, I don't know whether this would cause a problem on the client-side, but I could imagine that the client might run into class cast exceptions when invoking the seond bean after having invoked the first one...

                • 5. Re: 2 J2EE application with the same EJB
                  alessandro_rizzi Newbie

                  Thanks a lot for you suggestion, I'll try them as soon as I can.
                  For the clients call, they won't call both EJB at the same time, but some client will call the first EJB while some others will call the oter one, this (I hope) will not cause cast exception (client are deployed via JWS)
                  Regards
                  Alessandro Rizzi