0 Replies Latest reply on May 21, 2013 2:02 PM by tjuerge

    How to convert a maven-resolved EAR (with libraries and EJB moduls) into an archive supported by Arquillians enbedded OpenEJB container adapter?

    tjuerge

      Hi all,

       

      I'm trying to implement an integration test for a non-trivial maven-built JEE5 EAR with Arquillian and embedded OpenEJB.

       

      This EAR uses "META-INF/application.xml" to define the list of EJB moduls and the library directory (here WebLogics "APP-INF/lib/" is used). Due to the missing support of Arquillians embedded OpenEJB container adapter for the "application.xml" DD I have to convert the EAR into a WAR (libraries / EJB modules in "WEB-INF/lib/" and resources in "Web-INF/classes").

       

      Now I'm wondering how to implement this conversion effectively?

       

      Especially I'm interested in a solution for dealing with the ZipFileEntryAsset instances which are used for the content of the EnterpriseArchive returned by the following statement:

       

      EnterpriseArchive ear = Maven.resolver().loadPomFromFile("pom.xml").resolve("com.acme:product:ear:?").withoutTransitivity().asSingle(EnterpriseArchive.class);
      

       

      My current approach is as follows:

       

      1. Use IncludeRegExpPaths("/APP-INF/lib/.*") to get all libraries, convert them via ZipImporter into a JarArchive and add them as library ArchiveAsset to the WAR
      2. Use IncludeRegExpPaths("/APP-INF/classes/.*") to get all resources and add them as resource assets to the WAR
      3. Use IncludeRegExpPaths("/[^/]*.jar") to get the EJB modules, convert them via ZipImporter into a JarArchive and add them as library ArchiveAsset to the WAR

       

      To convert a single ZipFileEntryAsset into an ArchiveAsset I'm using the following workaround (here the variable "libNode" holds the content node with the ZipFileEntryAsset retrieved from the EARs library directory "/APP-INF/lib/"):

       

      JavaArchive libJar = ShrinkWrap.create(ZipImporter.class, libNode.getPath().get().substring("/APP-INF/lib/".length()))
                              .importFrom(libNode.getAsset().openStream()).as(JavaArchive.class);
      

       

      Is there a better solution for this?

       

      Thanks

      /Torsten