11 Replies Latest reply on Jan 9, 2013 4:54 AM by fbricon

    Jboss EE 6 EAR archetype, problem with EAR/lib

    shay1680

      Hi,

       

      I have used the Jboss EE 6 EAR archetype to create a new maven project , and it created 4 project/modules : project-ejb, project-war, project-ear, and project.

       

      When i add 3rd party libraries to to the project-ear , as expected they end up in EAR/lib  which should be visible to both project-ejb and project-war , but the IDE is showing "calls not found" errors whenever I try to reference 3rd party classes from the ejb or war projects.

       

      If i used the maven CLI to compile it works fine , and even deploying to jboss 7 works without any issues, but in the IDE i keep getting compile errors.

       

      Any advice?

       

      Thanks,

      Shay

        • 1. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
          maxandersen

          Did you use Existing Maven Project Import or Existing Eclipse project ?

           

          If you did not use the Maven variation eclipse will not use maven to resolve and configure your project and that would most definitely result in compile errors.

          • 2. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
            shay1680

            Hi Max,

             

            On eclipse Juno , I used the create new maven project wizard , with the  jboss maven archetype , specifically the one called  "Jboss -JavaEE6-webapp-ear-archtype" version "7.1.2-CR1"  .

             

            An unrelated issue , when i try to create a project by cliking on "Java EE EAR project" in the jboss central tab , if fails with the following error "failed to create project : root cause for artifact type {null,null,null} the group id cannot be empty".

             

            Thanks,

            Shay

            • 3. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
              maxandersen

              A) What compile errors are you getting when using the jboss maven archetype ?

               

              B) i've pinged Fred on the second issue in JBoss Central since that seems weird and should not happen for sure.

              • 4. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
                fbricon

                Are those dependencies also added as dependencies to your ejb/war project pom.xml?

                 

                Can you try creating a project using the multi-javaee6-archetype from http://open-archetypes.github.com/maven-repo/snapshots/ and study how dependencies are handled.

                 

                In Eclipse, first add the Open Archetypes catalog :

                * On the Archetypes Preferences page (Window > Preferences > Maven > Archetypes), click on the "Add Remote Catalog..." button

                * Catalog file : http://open-archetypes.github.com/maven-repo/snapshots/

                * Description : Open Archetypes (Snapshots)

                * Click OK to close the dialog

                * Click OK to close the preferences

                 

                Now you can create a new project, using the Maven wizard :

                * Create a new Maven project

                * Click Next to land on the Archetype page

                * Select the Open Archetypes (Snapshots) catalog

                * Check the "Include Snapshots" button

                * Select multi-javaee6-archetype and click Next

                * Enter the Group Id, Artifact Id and Version informations.

                 

                The generated project has a dependency on commons-lang3, which will end up in the ear lib/ directory.

                The ear declares (i.e provides) a dependency on logback, which brings the slf4j-api transitively, so other projects depending on that api will use the provided scope.

                 

                As for the null archetype issue, I need to look into it.

                • 5. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
                  shay1680

                  I have attched a few files to the thread:

                   

                  1) A screenshot of the wizard that appears when i click on the "Java EE project" on the jboss central tab. In the description box you can see "Project based on the null:null:null Maven archetype"  when the wizard is done no project is created.

                  2) A zip file containing the all the auto generated maven and eclipse files , after using the jboss-ee-6-web-ear 7.1.2 archetype  (test-ear)

                  3)A zip file containing the all the auto generated maven and eclipse files , after using the multi-javaee6-archetype from  http://open-archetypes.github.com/maven-repo/snapshots/  (test2)

                   

                  In both of the projects 2,3 I added a lightweight depndency to the ear maven (flexjson), when I try to use classes from flexjson in the ejb project, eclipse cannot resolve them.

                   

                  Only when i  specifically add the jars from EAR/lib to the ejb using the "build path" option of eclipse it fins those classes.

                   

                  Using mvn from command line works without any issues , so i assume this might be an issue with how eclispe handles the maven files.

                  • 6. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
                    snjeza

                    Try to add the EAR Libraries classpath container to your ejb and war projects (right-click the project, select Build Path>Configure Build Path..., select the Libraries tab, click the Add Library button and add EAR Libraries).

                    You will get the following line in project's .classpath:

                    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>

                     

                    I suppose m2e-wtp would have to add this container automatically to the projects included in an EAR.

                    This is a WTP container that sets EAR dependencies to an EAR module.

                    WTP sets this container when adding some WTP module to an EAR.

                    • 7. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
                      fbricon

                      Adding dependencies to an ear project doesn't make these dependencies available to the compilation classpath of its ejb/war/whatever modules.

                      Running mvn clean verify from your parent project folder clearly shows the ejb project doesn't compile.

                       

                      You need to remove the flexjson dependency from the ear project and add it to the ejb pom.xml instead.

                      That will add it to the project compilation classpath AND it will also be automatically deployed in the EAR's lib directory, as a transitive dependency.

                      Since the war project depends on the ejb, it'll see the flexjson jar as well. Now if the web project actually has a direct dependency towards flexjson,

                      you'll need to add it to the war pom.xml as well : it's one of maven best practices as it will protect your project in case the ejb removes the dependency in the future.

                      In that case,  the dependency should be added with a scope provided in the war pom.xml:

                      <dependency>

                                <groupId>net.sf.flexjson</groupId>

                                <artifactId>flexjson</artifactId>

                                <version>2.1</version>

                         <scope>provided</scope>

                      </dependency>

                      • 8. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
                        shay_matasaro

                        Snjezana,

                         

                        Yes, making manual changes does work, but I was trying to void those.

                         

                        Shay

                        • 9. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
                          shay_matasaro

                          Fred,

                           

                          Thank you, that clarified the issue, I was using the ear pom to add dependencies required for both EJB, and WAR.

                           

                          Thanks,

                          Shay

                          • 10. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
                            shay_matasaro

                            How do I mark this thread as "Solved"?

                             

                            My thread actions , show only :

                             

                            Thread Actions

                             

                                  Stop email notifications

                                  Send as email

                                  Report abuse

                                  Convert to article

                                  View as PDF

                                  View full screen

                                      Bookmark 

                                 ShareThis

                                  Report spam

                             

                            Shay

                            • 11. Re: Jboss EE 6 EAR archetype, problem with EAR/lib
                              fbricon

                              I have no idea. Links should be right below the message.

                              I took the liberty of flagging my reply as the proper answer.