3 Replies Latest reply: Mar 23, 2012 5:58 PM by Abhishekh Padmanabhan RSS

EJB3 packaging as jar archive in JBoss 4.2.3

Abhishekh Padmanabhan Newbie

I am trying to setup an intergration tests for an ejb project with the persistence context being different for the intergration tests. I would like to have the intergration test be executed as part of the maven execution that generates the actual build.  The difference would be that the actual build will generate a ejb jar that has the persistence.xml that points to oracle db but the packaging for integration tests using arquillian will general a jar that has the persistence.xml (available as test resource test-persistence.xml) that points to the in memory hsqldb.

 

Here is how I have my arquillian test setup to programatically replace  the persistence.xml using the shrinkwrap API.

 

    // this archive bundles the class files in target classes generated by the actual build including the persistence.xml in source resource that points to oracle db and additional test classes
    JavaArchive oracleEJBArchive = ShrinkWrap.create( JavaArchive.class,"async-ejb-test.jar").addClasses(edu.ksu.ome.asyc.test.AsyncITest.class, edu.ksu.ome.async.test.TestCommand.class, edu.ksu.ome.async.test.JNDITree.class);
    oracleEJBArchive.as(ExplodedImporter.class).importDirectory(new java.io.File("target/classes"));

     // this archive replaces the persitence.xml in the above generated archive with a test-persistence.xml that points to in-memory hsqldb
     JavaArchive hsqlEJBArchive = ShrinkWrap.create( JavaArchive.class,"async-ejb-hsql-test.jar").addAsManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"));
     // note how i am trying to exclude the original persistence.xml while merging from the  oracleEJBArchive source
     hsqlEJBArchive.merge(oracleEJBArchive, Filters.exclude(".*META-INF.*"));

 

The problem I am running into is for some reason the replaced persistence.xml is not being recongnized and the async-ejb-hsql-test.jar does not deploy as an EJB. The async-ejb-test.jar deploys just fine and i am sure the test persistence context for hsqldb is correct as if i have the persistence.xml point to the hsqld the jar deploys fine. So i am assuming it has to with the way i am progrmatically packaging the async-ejb-hsql-test.jar that the replaced persistence.xml as a manifest resource is unrecongonized.

 

Here are the exploded structure of the two jars. I guess on the replaced jar the manifest seems to added last. Could that be the issue. Is there a good way of programattically replacing the persistence.

 

  • Exploded package with the async-ejb-test.jar that works (note i can get this to work if use test-persistence.xml as the actual persistence.xml in src/resources/ without programatically constructing the ejb jar as above

ome@devvm:/as/data/jboss/ome/tmp/jsr88$ jar -xvf test.ear 
 inflated: lib/arquillian-testenricher-ejb.jar
 inflated: lib/arquillian-core.jar
 inflated: lib/arquillian-testenricher-resource.jar
 inflated: lib/arquillian-junit.jar
 inflated: lib/arquillian-testenricher-initialcontext.jar
 inflated: async-ejb-test.jar
 inflated: arquillian-protocol.war
 inflated: META-INF/application.xml
ome@devvm:/as/data/jboss/ome/tmp/jsr88$ jar -xvf async-ejb-test.jar 
 inflated: rebel.xml
  created: META-INF/
 inflated: META-INF/persistence.xml
  created: edu/
  created: edu/ksu/
  created: edu/ksu/ome/
  created: edu/ksu/ome/async/
  created: edu/ksu/ome/async/entity/
 inflated: edu/ksu/ome/async/entity/CommandStatus.class
 inflated: edu/ksu/ome/async/AsyncCommand.class
  created: edu/ksu/ome/async/lib/
 inflated: edu/ksu/ome/async/lib/StatusLib.class
 inflated: edu/ksu/ome/async/lib/StatusLibLocal.class
 inflated: edu/ksu/ome/async/lib/SchedulerLib.class
  created: edu/ksu/ome/async/ejb/
 inflated: edu/ksu/ome/async/ejb/SchedulerLibEJB.class
 inflated: edu/ksu/ome/async/ejb/DefaultListenerEJB.class
 inflated: edu/ksu/ome/async/ejb/ViewsEJB.class
 inflated: edu/ksu/ome/async/ejb/StatusLibEJB.class
  created: edu/ksu/ome/async/test/
 inflated: edu/ksu/ome/async/test/AsyncITest.class
 inflated: edu/ksu/ome/async/test/JNDITree.class
 inflated: edu/ksu/ome/async/test/TestCommand.class
 inflated: edu/ksu/ome/async/CommandState.class
  created: edu/ksu/ome/async/util/
 inflated: edu/ksu/ome/async/util/Services.class
 inflated: edu/ksu/ome/async/Util.class
  • Exploded package with the async-ejb-hsql-test.jar that fails

ome@devvm:/as/data/jboss/ome/tmp/jsr88$ jar -xvf test.ear 
 inflated: lib/arquillian-testenricher-ejb.jar
 inflated: lib/arquillian-core.jar
 inflated: lib/arquillian-testenricher-resource.jar
 inflated: lib/arquillian-junit.jar
 inflated: lib/arquillian-testenricher-initialcontext.jar
 inflated: arquillian-protocol.war
 inflated: async-ejb-hsql-test.jar
 inflated: META-INF/application.xml
ome@devvm:/as/data/jboss/ome/tmp/jsr88$ jar -xvf async-ejb-hsql-test.jar 
 inflated: rebel.xml
  created: edu/
  created: edu/ksu/
  created: edu/ksu/ome/
  created: edu/ksu/ome/async/
  created: edu/ksu/ome/async/entity/
 inflated: edu/ksu/ome/async/entity/CommandStatus.class
 inflated: edu/ksu/ome/async/AsyncCommand.class
  created: edu/ksu/ome/async/lib/
 inflated: edu/ksu/ome/async/lib/StatusLib.class
 inflated: edu/ksu/ome/async/lib/StatusLibLocal.class
 inflated: edu/ksu/ome/async/lib/SchedulerLib.class
  created: edu/ksu/ome/async/ejb/
 inflated: edu/ksu/ome/async/ejb/SchedulerLibEJB.class
 inflated: edu/ksu/ome/async/ejb/DefaultListenerEJB.class
 inflated: edu/ksu/ome/async/ejb/ViewsEJB.class
 inflated: edu/ksu/ome/async/ejb/StatusLibEJB.class
  created: edu/ksu/ome/async/test/
 inflated: edu/ksu/ome/async/test/AsyncITest.class
 inflated: edu/ksu/ome/async/test/JNDITree.class
 inflated: edu/ksu/ome/async/test/TestCommand.class
 inflated: edu/ksu/ome/async/CommandState.class
  created: edu/ksu/ome/async/util/
 inflated: edu/ksu/ome/async/util/Services.class
 inflated: edu/ksu/ome/async/Util.class
  created: META-INF/
 inflated: META-INF/persistence.xml

 

  • 1. Re: EJB3 packaging as jar archive in JBoss 4.2.3
    Abhishekh Padmanabhan Newbie

    The workaorund I have to switch the persistence.xml is to reconstruct the jar archive using the required packages as below and add the test-persistence.xml as a manifest resource.

     

    // this archive use the required packages to construct the ejb jar and add the test-persistence.xml as the manifest resource as replacing the persistence.xml in the source jar does not appear to work
    // the test persistence should ideally be loaded from a location outside the project instead of a project test resource using java.io.File to switch persistence context for builds
     JavaArchive javaArchive1 = ShrinkWrap.create( JavaArchive.class,"async-ejb-hsql-test.jar").addClasses(edu.ksu.ome.async.test.AsyncITest.class, edu.ksu.ome.async.test.TestCommand.class, edu.ksu.ome.async.test.JNDITree.class).addPackages(true, "edu.ksu.ome.async");
    javaArchive1.addAsManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"));
    
    // you can export this jar to a location in target so this can be reused when testing other ejbs that depend on this jar by add this as a ejb module to its test.ear archive instead of reconstructing it from the package
    javaArchive.as(ZipExporter.class).exportTo(new File("target/async-ejb-hsql-test.jar"));
    

     

    I would really prefer if i could use the jar generated by the build and just replace the persistence.xml instead of having to create another java archive using the package structure. I want to be able to reuse this jar as an ejb module to construct the tests for other ejbs

    that have a dependency ot it.

     

     

  • 2. Re: EJB3 packaging as jar archive in JBoss 4.2.3
    Aslak Knutsen Master

    Seems to be something wrong with the Filter in merge. Hvae to research that, but how about this:

     

     

    JavaArchive jar = ShrinkWrap.create(ExplodedImporter.class, "my.jar")
                            .importDirectory("import-folder").as(JavaArchive.class);
      
    jar.delete("META-INF/persistence.xml");
    jar.addAsManifestResource("test-persistence.xml", "persistence.xml");
    
  • 3. Re: EJB3 packaging as jar archive in JBoss 4.2.3
    Abhishekh Padmanabhan Newbie

    That looks to work.