1 Reply Latest reply on Aug 27, 2013 6:07 AM by aslak

    Glassfish with multiple deployments




      I am trying to deploy two jars in a Glassfish embedded test. Each jar holds a different JPA persistence unit connected to a different Derby database. The creation of the databases and the first deployment are completed successfully, but when the second deployment begins I get the following error message:


      SEVERE: Application with name test is already registered. Either specify that redeployment must be forced, or redeploy the application. Or if this is a new deployment, pick a different name.


      Subsequently the test fails.


      My deployment methods are the following:


          @Deployment(name = "joblet1" )
          public static JavaArchive deployJoblet1() {
              return ShrinkWrap.create(JavaArchive.class, "joblet1-jpa.jar")
                      .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
                      .addAsManifestResource("glassfish/joblet1-persistence.xml", "persistence.xml");
          @Deployment(name = "joblet2")
          public static JavaArchive deployJoblet2() {
              return ShrinkWrap.create(JavaArchive.class, "joblet2-jpa.jar")
                      .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
                      .addAsManifestResource("glassfish/joblet2-persistence.xml", "persistence.xml");


      My pom looks like below:




      When I disable one of the two deployments the test completes successfully.


      It looks like both deployments are performed under the same name (i.e. test) while I was expecting that the name of the deployments would be used (i.e. joblet1 and joblet2).

        • 1. Re: Glassfish with multiple deployments

          The reason for this is when using a Jar deployment combined with the Servlet Protocol, the Servlet Protocol need to be able to 'inject' a Servlet into the deployment somehow to communicate with the deployed resource. When this is not a WebArchive, it will wrap your JavaArchive inside a WebArchive. The final deployment is then a WebArchive. Being not too smart, and some other legacy issues with EJB lookup, the Servlet Protocol names this new Archive 'test.war'.


          So your two Jar files end up both being deployed as 'test.war'.


          You can read some more around how this works here;

          Servlet 3.0 - Arquillian - Project Documentation Editor


          The simplest workaround is to, instead of deploying two JavaArchives, make two WebArchives(containing the same stuff as in the JavaArchive v. just in the WebArchive locations). Then you're in control of the naming