3 Replies Latest reply on Oct 29, 2013 3:43 AM by Andrew Rubinger

    Add src/main/java to webarchive

    M Mudu Newbie

      Hi,

       

      I have created a webarchive by adding the packages under the src/main/java directory:

       

      @Deployment

        public static WebArchive createDeployment() {

       

        WebArchive war = ShrinkWrap

        .create(WebArchive.class, "test.war")

        .addPackages(true, "com.package1")

        .addPackages(true, "com.package2")

        .addPackages(true, "com.package3")

        .addPackages(true, "com.package4")

        .addPackages(true, "com.package5")

        .addPackages(true, "com.package6")

        .addPackages(true, "com.package7")

        .addAsResource(new File("src/main/resources/META-INF/persistence.xml"), "META-INF/persistence.xml")

        .addAsWebInfResource("jbossas-ds.xml")

        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

        war.writeTo(System.err, org.jboss.shrinkwrap.api.formatter.Formatters.VERBOSE);

        System.err.println();

        return war;

        }

       

      I have 20 packages under the /src/main/java directory and I do not want to add them to the web archive 1 by 1.  Is there a way to add all the packages?

      I have tried addAsDirectory("src/main/java") but it does not work.

       

      Thanks

        • 1. Re: Add src/main/java to webarchive
          Andrew Rubinger Master

          Unfortunately, you cannot add a source directory for "addPackages", as this works off bytecode available to the ClassLoader.

           

          Recommend:

           

          addPackages(boolean recursive,

             Filter<ArchivePath> filter,

             Package... packages)

           

          ...implement a Filter to pass through any packages with your desired prefix.


          S,

          ALR

          1 of 1 people found this helpful
          • 2. Re: Add src/main/java to webarchive
            M Mudu Newbie

            Thanks for the suggestion Andrew.  This is instead what I did:

             

            @RunWith(Arquillian.class)

            public class AccountUnitTest {

             

              @Deployment

              public static WebArchive createDeployment() {

             

              File[] libs = Maven.resolver()

                 .loadPomFromFile("pom.xml")

                 .resolve("org.apache.commons:commons-email:1.2",

                  "org.apache.lucene:lucene-analyzers-common:4.3.0",

                  "org.apache.sanselan:sanselan-incubator:0.97")

                 .withTransitivity().asFile();

             

              WebArchive war = ShrinkWrap

              .create(WebArchive.class, "test.war")

              .addPackages(true, "com.package.ejb.account")

              .addPackages(true, "com.package.ejb.entity")

              .addPackages(true, "com.package.ejb.compositekeys")

              .addPackages(true, "com.package.ejb.view")

              .addPackages(true, "com.package.ejb.indexing")

              .addPackages(true, "com.package.ejb.comment")

              .addPackages(true, "com.package.ejb.systemkeys")

              .addPackages(true, "com.package.ejb.mail")

              .addAsLibraries(libs)

              .addAsResource(new File("src/main/resources/META-INF/persistence.xml"), "META-INF/persistence.xml")

              .addAsWebInfResource("jbossas-ds.xml")

              .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

              war.writeTo(System.err, org.jboss.shrinkwrap.api.formatter.Formatters.VERBOSE);

              System.err.println();

              return war;

              }

             

              /*@PersistenceContext(unitName = "myapp")

                EntityManager em;

              

                @Inject

                UserTransaction utx;*/

             

              @EJB(mappedName="java:global/test/AccountBean!com.package.ejb.account.AccountLocal")

              AccountLocal accountLocal;

             

              @Test

              public void findUser(){

              UserValue user = accountLocal.findUser("admin");

              boolean userFound = false;

              if(user != null) {

              userFound = true;

              }

              Assert.assertTrue(userFound);

              }

             

            The test runs OK but I cannot debug while running the test.  I need to figure out how to Debug as JUnit test from Eclipse, and stop at a breakpoint.  In order for the test to run I start a JBoss 7.1.2 container.

            Any suggestions?

             

            Thanks

            • 3. Re: Add src/main/java to webarchive
              Andrew Rubinger Master

              For debugging, consider that you'll have two VMs; the client VM which launches the test and the server VM which contains the running JBossAS7 instance.  @see for example:

               

                http://lukas.fryc.eu/blog/2013/06/debugging-arquillian.html