1 2 Previous Next 26 Replies Latest reply on Feb 12, 2008 5:10 AM by doballve

    Maven2 example application for Seam2

    Cory Prowse Newbie

      Hi,

      I have made available for download a work in progress to getting a sample project going with Seam2 building and testing using Maven2 and JBossEmbedded. I thought a lot of the issues would be solved since there is a root pom provided for Seam (and hence the dependencies would be managed for me).

      Alas, I always get the following error from the first unit test that attempts to start Embedded JBoss (using the provided SeamTest class in Seam).

      ERROR [AbstractKernelController] Error installing to Instantiated: name=FileStructure state=Described
      java.lang.NoSuchMethodError: javassist.scopedpool.ScopedClassPool.<init>(Ljava/lang/ClassLoader;Ljavassist/ClassPool;Ljavassist/scopedpool/ScopedClassPoolRepository;Z)V
      at org.jboss.aop.classpool.AOPClassPool.<init>(AOPClassPool.java:69)


      I have archived an example application and provided it for download so that perhaps others can point me towards the correct means of achieving this.
      The project will build an EAR that successfully deploys and runs within Glassfish v2, however only if you skip the unit tests:
      mvn -Dmaven.test.skip=true clean install


      It uses the 2.0.1.CR1 root pom and the recently published beta3-SNAPSHOT of Embedded JBoss.
      It also will enforce using Java5 and Maven 2.0.8+ to ensure the environment is supported correctly.

      The archive can be obtained from here: http://www.users.on.net/~cory_prowse/seamMavenExample-20080102.zip

      Would love to get some help in getting this to work from anyone capable.
      Would it require the new version of JBoss Embedded to be released first?

      Hopefully those working on Seam and/or JBossEmbedded can review this before their respective projects make their next releases.

        • 1. Re: Maven2 example application for Seam2
          marx3 Apprentice

          Very good idea! We need something which works. Unfortunatelly I can't help because i'm not good with Maven

          • 2. Re: Maven2 example application for Seam2
            Pete Muir Master

             

            Would it require the new version of JBoss Embedded to be released first?


            Highly unlikely, there is nothing wrong with Seam or Embedded here, just the way Maven sets up the classpath when running tests.

            Hopefully those working on Seam and/or JBossEmbedded can review this before their respective projects make their next releases.


            Its not likely to happen for the next release, but perhaps 2.0.2

            • 3. Re: Maven2 example application for Seam2
              Cory Prowse Newbie

               

              "pete.muir@jboss.org" wrote:
              there is nothing wrong with Seam or Embedded here, just the way Maven sets up the classpath when running tests.


              Aha!

              The problem then appears to be with the thirdparty-all-beta*.jar file as it contains a separate copy of javassist.

              Adding an exclusion for javassist to jboss-seam and hibernate-entitymanager in the Ejb's POM as follows:
              <dependency>
               <groupId>org.jboss.seam</groupId>
               <artifactId>jboss-seam</artifactId>
               <exclusions>
               <exclusion>
               <groupId>jboss</groupId>
               <artifactId>javassist</artifactId>
               </exclusion>
               </exclusions>
               </dependency>
              ...
               <dependency>
               <groupId>org.hibernate</groupId>
               <artifactId>hibernate-entitymanager</artifactId>
               <exclusions>
               <exclusion>
               <groupId>jboss</groupId>
               <artifactId>javassist</artifactId>
               </exclusion>
               </exclusions>
               </dependency>


              causes the tests to now fail with:

              ERROR [AbstractKernelController] Error installing to Start: name=java:comp state=Create
              javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
               at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
               at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
               at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
               at javax.naming.InitialContext.lookup(InitialContext.java:351)
               at org.jboss.naming.JavaCompInitializer.start(JavaCompInitializer.java:83)


              So it appears the dependencies need to be properly and fully speced out in the appropriate poms.

              The use of these "*-all-*.jar" files appear the be the culprit.

              Namely:
              hibernate-all-*.jar
              jboss-embedded-all-*.jar
              thirdparty-all-*.jar


              These are not very useful in their current form for Maven.

              Unless someone knows of a way to exclude certain dependencies in the test scope within maven? (I can't see a way)

              • 4. Re: Maven2 example application for Seam2
                marx3 Apprentice

                I've tied to build your example but no luck:

                [INFO] [enforcer:enforce {execution: enforce-java}]
                [WARNING] Rule 1: org.apache.maven.plugins.enforcer.RequireJavaVersion failed with message:
                Detected JDK Version: 1.6.0-3 is not in the allowed range [1.5,1.6).
                


                • 5. Re: Maven2 example application for Seam2
                  marx3 Apprentice

                  i've change
                  [1.5,1.6)
                  to
                  [1.5,1.6.0-3]
                  and it went ahead

                  • 6. Re: Maven2 example application for Seam2
                    Cory Prowse Newbie

                    I don't believe Embedded JBoss supports Java6?

                    Also Postgres JDBC doesn't support Java6 so I have that enforcement in place for both of these reasons (the 1st one should apply to everyone)

                    • 8. Re: Maven2 example application for Seam2
                      marx3 Apprentice

                      everything compiled ok (1.6 is backwards compatible), i think you have mistake in right parenthese:
                      is: [1.5,1.6)
                      probably should be:[1.5,1.6]

                      There seems to be problem with local repository. I think I need to create one, but don't know how.

                      Downloading: http://repository.jboss.org/maven2/org/richfaces/ui/richfaces-ui/3.1.2.SP1/richfaces-ui-3.1.2.SP1.jar
                      1485K downloaded
                      Downloading: http://repository.jboss.org/maven2/concurrent/concurrent/1.3.4/concurrent-1.3.4.jar
                      Downloading: http://snapshots.jboss.org/maven2/concurrent/concurrent/1.3.4/concurrent-1.3.4.jar
                      Downloading: http://repo1.maven.org/maven2/concurrent/concurrent/1.3.4/concurrent-1.3.4.jar
                      184K downloaded
                      Downloading: http://repository.jboss.org/maven2/javax/servlet/jsp/jsp-api/2.1/jsp-api-2.1.jar
                      98K downloaded
                      [INFO] ------------------------------------------------------------------------
                      [ERROR] BUILD ERROR
                      [INFO] ------------------------------------------------------------------------
                      [INFO] Failed to resolve artifact.
                      
                      Missing:
                      ----------
                      1) au.prowse.cory.seammavenexample:seamMavenExampleEjbs:ejb-client:client:1.0-SNAPSHOT
                      
                       Try downloading the file manually from the project website.
                      
                       Then, install it using the command:
                       mvn install:install-file -DgroupId=au.prowse.cory.seammavenexample -DartifactId=seamMavenExampleEjbs -Dversion=1.0-SNAPSHOT -Dclassifier=client -Dpackaging=ejb-client -Dfile=/path/to/file
                      
                       Alternatively, if you host your own repository you can deploy the file there:
                       mvn deploy:deploy-file -DgroupId=au.prowse.cory.seammavenexample -DartifactId=seamMavenExampleEjbs -Dversion=1.0-SNAPSHOT -Dclassifier=client -Dpackaging=ejb-client -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
                      
                       Path to dependency:
                       1) au.prowse.cory.seammavenexample:seamMavenExampleWar:war:1.0-SNAPSHOT
                       2) au.prowse.cory.seammavenexample:seamMavenExampleEjbs:ejb-client:client:1.0-SNAPSHOT
                      
                      ----------
                      1 required artifact is missing.
                      
                      for artifact:
                       au.prowse.cory.seammavenexample:seamMavenExampleWar:war:1.0-SNAPSHOT
                      
                      from the specified remote repositories:
                       snapshots.jboss.org (http://snapshots.jboss.org/maven2),
                       central (http://repo1.maven.org/maven2),
                       repository.jboss.org (http://repository.jboss.org/maven2)
                      


                      • 9. Re: Maven2 example application for Seam2
                        Cory Prowse Newbie

                        This is just a cut down version of a much larger project of which I use Postgres with Glassfish for deployment testing (as Derby database doesn't work with jBPM). So I deliberately force that check that Java 1.6 is not run, meaning the right bracket is correct for a less than and not equal to condition.

                        Also cos this currently doesn't work, I wanted to ensure people were running Java5 which is more widely supported than Java6 to rule out any issues there.
                        I could be wrong there though :)

                        Checkout this link for more info:
                        http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution#DependencyMediationandConflictResolution-DependencyVersionRanges


                        As for your depenendency error, it's cos the project has not successfully compiled that project and so has not produced that artifact.
                        You need to first run it without tests:

                        mvn -Dmaven.test.skip=true clean install


                        That will ensure all projects are built and their artifacts available in your local repository.

                        • 10. Re: Maven2 example application for Seam2
                          marx3 Apprentice

                          Java6 can compile bytecode Java5 compatible, so I see no point in discriminating Java6. There should be an option to force that - I do that in Ant with

                          <property name="target" value="1.6"/>
                          <property name="source" value="1.6"/>
                          ...
                          <javac classpathref="build.classpath" destdir="${jar.dir}" debug="${javac.debug}" deprecation="${javac.deprecation}" source="${source}" target="${target}" nowarn="on" encoding="UTF-8">
                          ...
                          


                          Anyway with tests skipped your project has been built ok

                          • 11. Re: Maven2 example application for Seam2
                            Cory Prowse Newbie

                            Yup you are correct, and I have enabled the option to create Java5 bytecode in the parent pom.

                            <plugin>
                             <groupId>org.apache.maven.plugins</groupId>
                             <artifactId>maven-compiler-plugin</artifactId>
                             <configuration>
                             <!-- Java5 for portability - also Glassfish works only in Java5 for now -->
                             <source>1.5</source>
                             <target>1.5</target>
                             <maxmem>1024m</maxmem>
                             <optimize>true</optimize>
                             </configuration>
                             </plugin>


                            It still seems to be at the moment that the problem is those uberjars of "all" dependencies. Having the same class in more than one jar annoys the classloaders (cos they are not the same class then).

                            I could go through and create exclusions for all jars in those uberjars but then the final EAR for a production (or integration test) deployment would be without them as well.

                            • 12. Re: Maven2 example application for Seam2
                              Pete Muir Master

                              Yes, I don't like the -all.jar s particularly, however I don't see a nice way around it (Seam's deps are different than those in the -all.jar)

                              However, this will all go away when we can target JBoss AS 5 with Seam (as this is what Embedded is based on, and so we can sync jar versions easily). This should be soon.

                              I don't know how to order the classpath with Maven (it's easy with ant) but you need to make sure the -all jars come before everything else when running tests.

                              • 13. Re: Maven2 example application for Seam2
                                Cory Prowse Newbie

                                 

                                "pete.muir@jboss.org" wrote:
                                I don't know how to order the classpath with Maven (it's easy with ant) but you need to make sure the -all jars come before everything else when running tests.


                                Pete you are a legend (and not the Will Smith variety, I haven't seen that movie yet).

                                Maven orders the classpath in the same order as specified in the pom, and with Maven 2.0.8 they have ensured that the test classpath is first as well (the reason I enforce Maven version 2.08+ in the pom).

                                So I reordered the classpath and voila!
                                The error I get is now back to the "NoInitialContextException" which I can now work on.

                                Are there any other classpath ordering things that I should be aware of?

                                • 14. UPDATED Maven2 example application for Seam2
                                  Cory Prowse Newbie

                                  Alrighty I have made good progress!
                                  It works!

                                  Sorta...

                                  There seems to be a problem with either Embedded JBoss or Maven (most likely Maven).
                                  As an aside, I had to roll back to Embedded JBoss beta2 as beta3 was failing with JMS related stuff.

                                  The example application will fail to build, complaining about no default persistence unit in the deployment, which is due to the test classpath not including the

                                  src/test/resources/META-INF/persistence.xml


                                  To make it work copy or move this file to
                                  src/main/resources/META-INF/persistence.xml


                                  I'm confused why it isn't working as the META-INF directory in the test resources does contain another file that is picked up during the test by JBoss Embedded.

                                  So it appears that Maven (or Embedded JBoss) is ignoring the persistence.xml file in the test resources!??

                                  This is using Maven 2.0.8 which explicitly states in its release notes:
                                  MNG-3118 - Test-classes should come before classes in the classpath. This may slightly alter behavior of tests. The test-classes is now included first in the classpath to allow test resources to override normal runtime ones.


                                  I do not want to use filters in Maven as this file should only be used in unit tests and not included in any packaged artifacts.

                                  The updated example can be downloaded from here:
                                  http://www.users.on.net/~cory_prowse/seamMavenExample-20080104.zip

                                  I'm going to post the example app to the Maven users mailing list and see if anyone there knows what is going on.

                                  1 2 Previous Next