1 Reply Latest reply on Mar 30, 2012 7:21 AM by Veit Guna

    Updating application.xml within ear

    Veit Guna Newbie

      Hi.

       

      I've got an already packaged production .ear. My plan is to add test classes to have a nearly-production like deployment.

      For this I add a test.jar with all test jar's I need. When I add it via:

       

      {code}

       

      @Deployment

      public static EnterpriseArchive deploy() {

      EnterpriseArchive ear = IntegrationTest.deploy();

       

      JavaArchive archive = ShrinkWrap.create(JavaArchive.class,"tests.jar")

      .addClasses(TestDocumentCreatedEventProcessor.class, EventServiceIT.class, IntegrationTest.class)

      .addAsResource("META-INF/beans.xml");

       

      System.out.println(archive.toString(true));

       

      ear.addAsModule(archive);

       

      System.out.println(ear.toString(true));

       

      return ear;

      }

       

      {code}

       

      I would expected, that the given test.jar will be added to the existing application.xml. But it doesn't. Is that a bug or by design ?

      Theoretically addAsModule has all information it needs to perform this task or am I missing something?

       

      How would I perform a modification of the existing application.xml?

       

      BTW: IntegrationTest.deploy() reads the production .ear via ShrinkWrap.createFromZipFile().

       

      Thanks

      Veit

        • 1. Re: Updating application.xml within ear
          Veit Guna Newbie

          Ok, I'll figured it out. For everyone who's interested - that works for me:

           

           

          {code}

          ...

          ...

          ear.addAsModule(archive);


          Node node = ear.get("META-INF/application.xml");

          DescriptorImporter importer =  Descriptors.importAs(ApplicationDescriptor.class, "test");
          ApplicationDescriptor desc = (ApplicationDescriptor) importer.from(node.getAsset().openStream());

          // seems that ejbModule/javaModule simply appends. that violates the xsd. so removing probably existing library-directory
          // and adding it later on
          String xml = desc.exportAsString();
          xml = xml.replaceAll("<library-directory>lib<\\/library-directory>", "");

          desc = (ApplicationDescriptor) importer.from(xml);
          desc.javaModule("tests.jar");
          desc.libraryDirectory("lib");

          Asset asset = new StringAsset(desc.exportAsString());

          ear.delete(node.getPath());
          ear.setApplicationXML(asset);

          return ear;

           

          {code}

           

          BTW: I HATE this editor.