Uploaded image for project: 'Arquillian'
  1. Arquillian
  2. ARQ-593

glassfish-resources.xml (application scoped resources) not loaded with glassfish-remote

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 1.0.0.Alpha5
    • Fix Version/s: None
    • Component/s: GlassFish Containers
    • Labels:
      None
    • Environment:
      MacOSX Lion, Maven 3, arquillian 1.0.0.Alpha5, arquillian-glassfish-remote-3.1 1.0.0.Alpha5, Glassfish 3.1.1, Java 1.6.0_26 64bits

      Description

      An EJB Jar with an glassfish-resources.xml references an jdbc/rt JNDI resource.
      It's correctly read as java:app/jdbc/rt by the EJB package generated by maven but failed with Arquillian/ShrinkWrap targeting glassfish-remote-3.1

      ShrinkWrap :

      JavaArchive archive =
      ShrinkWrap.create(JavaArchive.class, "Project-ejb-1.0.0-SNAPSHOT.jar")
      .addPackages(true, "com.company.project.ejb.entities")
      .addPackages(true, "com.company.project.ejb.model")
      .addAsManifestResource("META-INF/ejb-jar.xml", ArchivePaths.create("ejb-jar.xml"))
      .addAsManifestResource("META-INF/sun-ejb-jar.xml", ArchivePaths.create("sun-ejb-jar.xml"))
      .addAsManifestResource("META-INF/glassfish-resources-test.xml", ArchivePaths.create("glassfish-resources.xml"))
      .addAsManifestResource("META-INF/persistence-test.xml", ArchivePaths.create("persistence.xml"));

      persistence.xml :

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
      <persistence-unit name="RTUnit" transaction-type="JTA">
      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

      <jta-data-source>java:app/jdbc/rt</jta-data-source>

      <exclude-unlisted-classes>false</exclude-unlisted-classes>
      </persistence-unit>

      </persistence>

        Gliffy Diagrams

          Activity

          Hide
          vineet.reynolds Vineet Reynolds added a comment - - edited

          The posted code fails (on both embedded and remote GF), as glassfish-resources.xml is expected to be present in the top-level of the archive. Arquillian eventually creates a WAR file for deployment onto Glassfish, and hence, the glassfish-resources.xml is expected to be present in WEB-INF/glassfish-resources.xml; instead, the posted code places glassfish-resources.xml in WEB-INF/lib/Project-ejb-1.0.0-SNAPSHOT.jar#META-INF/glassfish-resources.xml.

          The suggested workaround is to explicitly create a WebArchive with a glassfish-resources.xml in the WEB-INF directory, as shown in the below example:

          	@Deployment
          	public static WebArchive createDeployment()
          	{
          		JavaArchive ejbArchive = ShrinkWrap.create(JavaArchive.class, "test-ejb.jar")
          				.addClasses(GreetingManager.class, GreetingManagerBean.class, User.class)
          				.addAsResource("META-INF/ejb-jar.xml", "ejb-jar.xml")
          				.addAsResource("META-INF/persistence-test.xml", "META-INF/persistence.xml");
          		
          		return ShrinkWrap.create(WebArchive.class, "test.war")
          				.addAsLibrary(ejbArchive)
          				.addAsWebInfResource("META-INF/glassfish-resources-test.xml", "glassfish-resources.xml");
          	}
          

          To summarize: the WAR archive deployed by Arquillian to Glassfish is a single module (although it contains EJBs). The glassfish-resources.xml is expected to be present in the top-level archive in the WEB-INF directory for the resources to be application scoped. Also, if module-scoped resources are to be used, an EnterpriseArchive must used for deployment with the glassfish-resources.xml file present in the EJB jar, as a WebArchive is treated as a single module (despite the EJB classes in WEB-INF/classes or WEB-INF/lib).

          Show
          vineet.reynolds Vineet Reynolds added a comment - - edited The posted code fails (on both embedded and remote GF), as glassfish-resources.xml is expected to be present in the top-level of the archive. Arquillian eventually creates a WAR file for deployment onto Glassfish, and hence, the glassfish-resources.xml is expected to be present in WEB-INF/glassfish-resources.xml; instead, the posted code places glassfish-resources.xml in WEB-INF/lib/Project-ejb-1.0.0-SNAPSHOT.jar#META-INF/glassfish-resources.xml. The suggested workaround is to explicitly create a WebArchive with a glassfish-resources.xml in the WEB-INF directory, as shown in the below example: @Deployment public static WebArchive createDeployment() { JavaArchive ejbArchive = ShrinkWrap.create(JavaArchive.class, "test-ejb.jar") .addClasses(GreetingManager.class, GreetingManagerBean.class, User.class) .addAsResource("META-INF/ejb-jar.xml", "ejb-jar.xml") .addAsResource("META-INF/persistence-test.xml", "META-INF/persistence.xml"); return ShrinkWrap.create(WebArchive.class, "test.war") .addAsLibrary(ejbArchive) .addAsWebInfResource("META-INF/glassfish-resources-test.xml", "glassfish-resources.xml"); } To summarize: the WAR archive deployed by Arquillian to Glassfish is a single module (although it contains EJBs). The glassfish-resources.xml is expected to be present in the top-level archive in the WEB-INF directory for the resources to be application scoped. Also, if module-scoped resources are to be used, an EnterpriseArchive must used for deployment with the glassfish-resources.xml file present in the EJB jar, as a WebArchive is treated as a single module (despite the EJB classes in WEB-INF/classes or WEB-INF/lib).
          Hide
          kabhal Hugo de Paix de Coeur added a comment -

          workaround works fine

          Show
          kabhal Hugo de Paix de Coeur added a comment - workaround works fine

            People

            • Assignee:
              vineet.reynolds Vineet Reynolds
              Reporter:
              kabhal Hugo de Paix de Coeur
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development