4 Replies Latest reply on Jan 26, 2012 4:18 AM by predrag

    Deploying multiple wars in one jvm caused DuplicateServiceException

    yangju

      We are deploying multiple wars (no ear) into one jvm. Each war has its own web context and name. Each war's web-inf/lib has same persistence.jar.

      In this jar, a persistence.xml is defined. In this persistence.xml, we define a jndi for EntityMangerFactory such as:

      <property name="jboss.entity.manager.factory.jndi.name"

                      value="java:jboss/EntityManagerFactories/myEMF" />

       

      Since each war contains a jar which tries to register an emf with the same jndi name, deployments of every war fails with:

      Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.naming.context.java.jboss.EntityManagerFactories.myEMF is already registered.

       

      Perviously we used jboss AS 6 and ear deployments with multiple ears and we did not have such problem.

      In jboss 7, we decided to deploy war directly. But now we are stuck on this.

       

      Is there way to isolate war deployment? We could move the persistence.xml from the persistence.jar to the war directly, but then we would have to duplicate the persistence.xml into serveral wars. It is nice to have this file in a central location (a jar) and every war simply includes this jar in the classpath.

       

      If we can parameterize the jndi name so that the parameter can be replaced at deployment time by war's deployment unit name, that would work too. But how to parameter the jndi name to incldue deployment unit name in it?

       

      Thanks.

        • 1. Re: Deploying multiple wars in one jvm caused DuplicateServiceException
          jaikiran

          yangju wrote:

           

          We are deploying multiple wars (no ear) into one jvm. Each war has its own web context and name. Each war's web-inf/lib has same persistence.jar.

          In this jar, a persistence.xml is defined. In this persistence.xml, we define a jndi for EntityMangerFactory such as:

          <property name="jboss.entity.manager.factory.jndi.name"

                          value="java:jboss/EntityManagerFactories/myEMF" />

           

          Since each war contains a jar which tries to register an emf with the same jndi name, deployments of every war fails with:

          Caused by: org.jboss.msc.service.DuplicateServiceException: Service jboss.naming.context.java.jboss.EntityManagerFactories.myEMF is already registered.

           

          Perviously we used jboss AS 6 and ear deployments with multiple ears and we did not have such problem.

          In jboss 7, we decided to deploy war directly. But now we are stuck on this.

           

          I'm not sure how that even worked in AS6. I would have expected a duplicate JNDI binding name problem. My guess is that the second war used to overwrite the first war's JNDI name, which in itself is a bug.

           

           

          yangju wrote:

           

           

          If we can parameterize the jndi name so that the parameter can be replaced at deployment time by war's deployment unit name, that would work too. But how to parameter the jndi name to incldue deployment unit name in it?

           

           

          That is something that you could at build time. But then again, if the JNDI name is being referred in your code (I think it is), then that code needs to know of this dynamic JNDI name too. How do you make use of that JNDI name? If there are no references to that JNDI name in your code, then just not binding to the JNDI is an option.

          • 2. Re: Deploying multiple wars in one jvm caused DuplicateServiceException
            predrag

            Hi yangju, have you found the solution to this problem? I'm having the exact situation and still can't deploy wars...

            • 3. Re: Deploying multiple wars in one jvm caused DuplicateServiceException
              ctomc

              Predrag hi and welcome to forums,

               

              this is not a problem with AS7 but general problem in your application. JNDI is global and jndi name that you are using registers itself under global name that must be unique.

               

              What you can do is bind the name to be application/war scoped so you can bind it under name(s):

               

              java:comp/env/<your name>

              /<your name> (not necessary to works)

              or just <your name> for example EntityManagerFactories/myEMF

               

              but as Jaikiran already said, the fact that this ever worked in AS6 was horrible bug.

               

              On the other hand why do you even need this jndi bindig of EntityManagerFactory? are you accessing your EMF directly from JDNI even from outside of the application?

              If not, you can just comment out this line of configuration and application will deploy without any problems.

               

              cheers,

              tomaz

              • 4. Re: Deploying multiple wars in one jvm caused DuplicateServiceException
                predrag

                Hi Tomaž and thanks!

                 

                Mine persistence.xml contained following line:

                <property name="jboss.entity.manager.factory.jndi.name" value="java:/sleep-profiler-EntityManagerFactory"/>

                which caused the problem when database module (compiled as JAR) was included in multiple wars.

                 

                I thought that this line was necessary for everything to work well. I was wrong

                I removed this line from persistence.xml and now everything works just fine.

                 

                Thanks a lot!