Skip to main content

Seam (FCS) On GlassFish

Posted by rogerk on July 25, 2006 at 10:45 AM PDT

So far we've seen how we can get Seam running on GlassFish with Hibernate Persistence and Java Persistence. Modifications were needed to the Seam core classes as well as the application classes. Fortunately, JBoss has made the modifications to their core classes in time for their Seam FCS release. In this entry we'll outline the steps to get the Seam FCS release up and running on GlassFish with Java Persistence.



Prerequisites:

  1. A working build environment with ant,
    at least JDK 5,
    and GlassFish
    (build 43 or later).
  2. You'll need to use some of the Hibernate libraries that the Seam framework depends on:
    • Download and install href="http://sourceforge.net/project/showfiles.php?group_id=40712&package_id=127784&release_id=405151">Hibernate3
      3.2cr1.
    • Download and install href="http://sourceforge.net/project/showfiles.php?group_id=40712&package_id=156160&release_id=405227">Hibernate
      EntityManager 3.1 beta7 .  Note that style="font-style: italic;">hibernate-entitymanager.jar is not
      required because we'll be using Java Persistence.  However, style="font-style: italic;">hibernate-annotations.jar is still
      required, because the Seam framework uses classes from the Hibernate style="font-style: italic;">validator package.
    • Copy the required hibernate jars into Glassfish lib dir.
      The script href="http://weblogs.java.net/blog/rogerk/archive/copyHibernateLibsJPersist.sh">here
      contains the list of jars.
    • Edit the script to make sure it references your Glassfish and
      Hibernate install directories.
    • Execute the script.

Seam Setup:

  1. Download and install the Seam 1.0.1.GA release from href="http://sourceforge.net/project/showfiles.php?group_id=22866&package_id=163777&release_id=425718">here. 
    You should see a jboss-seam-1.0.1.GA directory.
  2. Get the zip file: href="http://weblogs.java.net/blog/rogerk/archive/seam-1.0.1.GA-booking-patch.zip">seam-1.0.1.GA-booking-patch.zip

  3. Go to the jboss-seam-1.0.1.GA directory and unzip
    seam-1.0.1.GA-booking-patch.zip.

Compilation Procedure:

  1. Copy jboss-seam-1.0.1.GA/lib/thirdparty-all.jar to style="font-style: italic;"><glassfish install dir>/lib 
  2. Compile Seam core classes - this will compile the HtmlLink class in the ui package.
    • Go to the jboss-seam-1.0.1.GA directory
    • ant
  3. Compile Seam Booking Application:
    • Go to the jboss-seam-1.0.1.GA/examples/booking directory
    • ant

Deploy the application:

  1. Start up Glassfish.
  2. Start the database:  <glassfish
    install dir>
    /bin/asadmin
    start-database
  3. Deploy jboss-seam-1.0.1.GA/examples/booking/build/jboss-seam-booking.ear

Load the database:

  1. Go to jboss-seam-1.0.1.GA/examples/booking/resources
  2. set your CLASSPATH so that it is:
    • CLASSPATH=<glassfish install dir>/javadb/lib/derbyclient.jar: style="font-style: italic;"><glassfish install dir>/javadb/lib/derbytools.jar: style="font-style: italic;"><glassfish install dir>/javadb/lib/derby.jar:.
  3. java -Dij.driver='org.apache.derby.jdbc.ClientDriver'
    org.apache.derby.tools.ij
  4. At the Derby ij prompt connect to the default database:
    • connect 'jdbc:derby://localhost:1527// style="font-style: italic;"><glassfish install dir>/bin/sun-appserv-samples';
      • For example: connect
        'jdbc:derby://localhost:1527///home/work/glassfish/bin/sun-appserv-samples';
    • run 'import.sql';
  • Now the Seam application tables should be loaded.

Run the application:

  • visit localhost:8080/seam-booking

Code Change Summary



The following changes apply to the Seam Booking application:


./examples/booking/resources/import.sql

style="font-style: italic;">---->
Added trailing semicolons to each sql statement


./examples/booking/resources/META-INF/persistence.xml

style="font-style: italic;">---->
Updated for application with
GlassFish
and Java
Persistence


./examples/booking/resources/META-INF/ejb-jar.xml

style="font-style: italic;">---->
Updated per EJB 3 schema: added schema namespace and style="font-style: italic;"><interceptors>
element


./examples/booking/resources/WEB-INF/web.xml

style="font-style: italic;">---->
Added schema namespace
---->Updated JNDI lookup pattern
---->Disabled MyFaces StartupServletContextListener - we're using JSF 1.2
---->Added style="font-style: italic;"><ejb-local-ref>
elements for EJB applicaton actions


./examples/booking/src/org/jboss/seam/example/booking/RegisterAction.java

./examples/booking/src/org/jboss/seam/example/booking/HotelSearchingAction.java

./examples/booking/src/org/jboss/seam/example/booking/BookingListAction.java

./examples/booking/src/org/jboss/seam/example/booking/LoginAction.java

style="font-style: italic;">---->
Updated sql statements passed to EntityManager.createQuery


./examples/booking/src/org/jboss/seam/example/booking/User.java

style="font-style: italic;">---->Refer to table name 'Users'


./examples/booking/view/conversations.xhtml

style="font-style: italic;">---->Added <ui:composition> element


The following change is to a Seam (JSF) custom component:

./src/ui/org/jboss/seam/ui/HtmlLink.java

style="font-style: italic;">---->Added encodeEnd method to properly end either an HTML input element or an HTML hyperlink element




All of these entries are in the seam-1.0.1.GA-booking-patch.zip file and can be reviewed.

Related Topics >>