Official Seam demo app for Glassfish
Wednesday, November 29th, 2006As an application framework for Java EE 5.0, JBoss Seam works on both JBoss and Glassfish application servers (see Riger Kitain and Brian Leonard's blogs). From Seam 1.1, we will officially maintain the Hotel Booking example application for Glassfish. To use it, just go to the examples/glassfish directory, run ant, and then deploy the build/jboss-seam-glassfish.ear application into Glassfish. The application is available at http://localhost:8080/jboss-seam-glassfish. The example is in CVS now and it should be available in distributions from Seam 1.1 CR2.
But of course, the Hotel Booking is just one example. How do you port other Seam apps to Glassfish? Here are how.
Choose the Hibernate JPA
First, let's be clear that we highly recommend you use Hibernate as the JPA (Java Persistence API) provider in Glassfish. By default, Glassfish uses "TopLink Essentials" (a.k.a the watered-down "lesser TopLink") for JPA implementation. It might be fine for basic JPA needs but Seam makes good use of Hibernate specific features such as Hibernate validators and filters etc. In fact, it would be foolish not to use the Hibernate JPA with Seam considerring how easy it is to install Hibernate JPA in Glassfish.
By including Hibernate JARs in your EAR, you can enable Hibernate JPA for a single application. Or you can simply copy Hibernate JARs to Glassfish's lib directory and enable Hibernate JPA for all applications. To use the Hibernate JPA, just choose the proper persistence provider in your persistence.xml as we do below.
If you have to use the "lesser TopLink" JPA, we also have a toplink build target in the examples/glassfish project. But be aware that you need to load the database manually for the hotel data since TopLink does not read the import.sql file.
Diff JBoss Glassfish
All the changes from a JBoss deployment to a Glassfish deployment concern the configuration files and library JARs only.
Since Glassfish uses the JSF RI not MyFaces, you should first make sure that the MyFaces phrase listener is turned off. Just comment the following lines out in web.xml
-
<!-- MyFaces -->
-
<!--
-
<listener>
-
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
-
</listener>
-
-->
Glassfish requires you to declare all EJB3 session bean reference names in the web.xml file for the web application to access the beans. This is a rather tedious process. But you have to add the following lines in web.xml for each session bean in your application.
-
<ejb-local-ref>
-
<ejb-ref-name>jboss-seam-glassfish/BookingListAction/local</ejb-ref-name>
-
<ejb-ref-type>Session</ejb-ref-type>
-
<local>org.jboss.seam.example.booking.BookingList</local>
-
<ejb-link>BookingListAction</ejb-link>
-
</ejb-local-ref>
You also need to tell Seam the session bean naming pattern you just used in web.xml, so that Seam can locate those beans. So, make sure you have the following in components.xml file.
-
<core:init jndi-pattern="java:comp/env/jboss-seam-glassfish/#{ejbName}/local" debug="true"/>
In order to use the Hibernate JPA with Glassfish's buid-in JavaDB (Derby database), you need a persistence.xml file like the following.
-
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-
-
<persistence-unit name="bookingDatabase">
-
-
<provider>org.hibernate.ejb.HibernatePersistence</provider>
-
<jta-data-source>jdbc/__default</jta-data-source>
-
<properties>
-
-
<property name="hibernate.dialect"
-
value="org.hibernate.dialect.DerbyDialect"/>
-
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
-
<property name="hibernate.show_sql" value="true"/>
-
-
<property name="hibernate.cache.provider_class"
-
value="org.hibernate.cache.HashtableCacheProvider"/>
-
</properties>
-
</persistence-unit>
-
</persistence>
Finally, you need to bundle the following JAR files in your EAR in addition to any libary files you already need for JBoss deploment (e.g., jboss-seam-*.jar, facelets JARs, and Ajax4jsf JARs etc.)
-
hibernate*.jar: Hibernate3, Annotation, EntityManager JARs
-
thirdparty-all.jar: Third party JARs for Hibernate JPA outside of JBoss AS
-
jboss-archive-browsing.jar: Required for Hibernate EntityManager
-
commons-beanutils-1.7.0.jar: Required by Seam outside of JBoss AS
-
commons-digester-1.6.jar: Required by Seam outside of JBoss AS
That's it. Now enjoy!












