I am just succesfully customized Seam 2 JPA example to deploy and run on JBoss AS 7 server, so I will share steps which are required to do for that.

 

First JBoss AS 7 is great in start up time, deployment time, classloading isolation and much more. See JBoss AS7 page for more and detailed description!

 

Just quick info - Seam 2 JPA example is demonstrating JPA 1 usage, it uses JSF 1.2 and Richfaces 3.3.3.Final. Thanks to great classloading isolation Seam 2 can live and works just fine in JBoss AS7 although it is primarily targeted for Java EE 6, where are JSF2, JPA 2.

 

First step in customizing the example is set up of datasource. JBoss AS 7 release is changing the name of default datasource, which is for demos/examples. Now the default datasource is called java:jboss/datasources/ExampleDS, you have to just change the referenced datasource JNDI in the example or create new datasource with old name java:/DefaultDS.

 

I created new datasource with old name, because I am using many old examples and I don't want to change them all. New datasource is basically a clone of existing ExampleDS.

 

Start Jboss AS7 standalone instance by writing in terminal:

<installed_path_to_jbossas7>/bin/standalone.sh(on linux)
<installed_path_to_jbossas7>/bin/standalone.bat(on windows)

In another terminal window start CLI admin interface by:

<installed_path_to_jbossas7>/bin/jboss-admin.sh --connect(on linux)
<installed_path_to_jbossas7>/bin/jboss-admin.bat --connect(on windows)

Then write the command for creating actual datasource:

add-data-source --jndi-name=java:/DefaultDS --connection-url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 --username=sa --password=sa --pool-name=DefaultDS_pool --driver-name=h2

 

The above command is self describing ;-).

 

Now a few customizations which are done in jboss-seam-jpa.war:

  1. Remove jboss-web.xml from jboss-seam-jpa.war/WEB-INF/ - defined class loading in jboss-web.xml is now default behaviour.

  2. Comment or remove hibernate property

    <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>

    in jboss-seam-jpa.war/WEB-INF/classes/META-INF/persistence.xml

     

  3. Add the following dependencies from seam distribution (seam/lib directory) into jboss-seam-jpa.war/WEB-INF/lib directory, which are in JBoss AS 5/6 in different versions:
    slf4j-api.jar
    slf4j-log4j12.jar

    hibernate-core.jar
    hibernate-entitymanager.jar
    hibernate-validator.jar
    hibernate-annotations.jar
    hibernate-commons-annotations.jar
  4. Create new file jboss-deployment-structure.xml and add it to jboss-seam-jpa.war/WEB-INF/ with the following content:
<jboss-deployment-structure> 
   <deployment>
        <exclusions>
          <module name="javax.faces.api" slot="main"/>
          <module name="com.sun.jsf-impl" slot="main"/>
        </exclusions>
        <dependencies>
          <module name="org.apache.commons.logging" />
          <module name="org.apache.commons.collections" />
          <module name="org.apache.log4j" />
          <module name="org.dom4j" />
          <module name="javax.faces.api" slot="1.2"/>
          <module name="com.sun.jsf-impl" slot="1.2"/>
        </dependencies>
    </deployment>   
</jboss-deployment-structure>

 

 

I will shortly describe why I did step 3 and 4. By default Jboss AS 7 is configured for JSF2, but Seam 2 is integrated with JSF 1.2, so thanks to class loading isolation we can have in Jboss AS 7 set up more than one version of the same library in our case JSF 1.2 and JSF 2. Both JSF's implementations are preconfigured in AS7 release, we just have to include 1.2 slot and default JSF 2  to exclude from web application deployment. The remaining two dependencies – dom4j and commons logging is provided by container and Seam 2 expects them as provided.

 

Last step 4 is replacement of provided hibernate dependencies and their dependencies, which are bundled directly in web application WEB-INF/lib subdirectory. This is because Seam 2 is integrated with older hibernate versions which is not backward compatible with hibernate what is in AS7.

 

Enjoy new JBoss AS 7 with „old“ Seam2!