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

    Glassfish 3.1.2.2 with multiple deployments

    bissaias

      Hi,

       

      I am trying to deploy two jars in a Glassfish 3.1.2.2 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")
                      .addPackage(Professor.class.getPackage())
                      .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")
                      .addPackage(Professor2.class.getPackage())
                      .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
                      .addAsManifestResource("glassfish/joblet2-persistence.xml", "persistence.xml");
          }
      

       

      My pom looks like below:

       

                  <dependencies>
                      <dependency>
                          <groupId>org.jboss.arquillian.container</groupId>
                          <artifactId>arquillian-glassfish-embedded-3.1</artifactId>
                          <version>1.0.0.CR4</version>
                      </dependency>
                      <dependency>
                          <groupId>org.glassfish.main.extras</groupId>
                          <artifactId>glassfish-embedded-web</artifactId>
                          <version>3.1.2.2</version>
                      </dependency>
                  </dependencies>
      

       

      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 3.1.2.2 with multiple deployments
          aslak

          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