SeamFramework.orgCommunity Documentation

Chapter 39. Seam on Glassfish application server

39.1. Glassfish environment and deployment information
39.1.1. Installation version and tips
39.2. The jee5/booking example
39.2.1. Deploying the application to Glassfish
39.3. The jpa booking example
39.3.1. Building the jpa example
39.3.2. Deploying the jpa example
39.3.3. What's different for Glassfish v2 UR2
39.4. Deploying an application generated by seam-gen on Glassfish v2 UR2
39.4.1. Running seam-gen Setup
39.4.2. Changes needed for deployment to Glassfish

Glassfish is an open source application server which fully implements Java EE 5. The latest stable release is v2 UR2.

First we will go over some basic information about the Glassfish environment that we used for these examples. We will go over the details of those steps with the jee5 example. We will also deploy the JPA example application. Finally we show customizing of seam-gen's generated application.

Glassfish is a open source project and its installation is very easy. This section will detail the exact server versions used and installation tips.

All of the examples and information in this chapter are based on the the latest version of Glassfish at the time of this writing.

After downloading suitable jar file with Glassfish, install it by writing on command line in case of linux version:

java -Xmx256m -jar
					glassfish-installer-v2ur2-b04-linux.jar

After installing, setup glassfish, the following command creates Glassfish server domain:

cd glassfish; ant -f setup.xml

The created domain name is domain1.

Start the embedded JavaDB server:

bin/asadmin start-database
				

This is default embedded database server in Glassfish.

Start the Glassfish server domain1:

bin/asadmin start-domain domain1
				

The deployment and configuration is available at the Web Administration console at http://localhost:4848/. Access the web admin console with default username/password: admin/adminadmin. You can also copy EAR/WAR file to glassfish/domains/domain1/autodeploy for quick automatic deployment.

Stopping the server and database can be done by the following command:

bin/asadmin stop-domain domain1;
					bin/asadmin stop-database

The jee5/booking example is based on the Hotel Booking example (which runs on JBoss AS). Out of the box it is also designed to run on Glassfish. It is located in the $SEAM_DIST/examples/jee5/booking directory.

This is the Hotel Booking example implemented in Seam POJOs and using Hibernate JPA with JPA transactions. It does not require EJB3 support to run on application server.

The example already has a break-out of configurations and build scripts for many of the common containers including Glassfish.

First thing we are going to do is build and deploy that example.

This is very similar to the jee5 example at Section 39.2.1, “Deploying the application to Glassfish” .

  • Log in to the administration console

    http://localhost:4848
    						

  • Access the Web Applications in the menu option under the Applications left side menu.

    • Preparing for the application installation

      • Browse to the examples/jpa/dist-glassfish/jboss-seam-jpa.war file using the file upload widget.

      • Select the OK button.

    • You can now access the application at http://localhost:8081/jboss-seam-jpa/ .

Using Derby instead of Hypersonic SQL DB

In order for the app to work out of the box with Glassfish, we have used the Derby (i.e., Java DB) database in Glassfish. However, we strongly recommend you to use a non-Derby data source (e.g., HSQL is a much better embeded DB) if possible. The examples/jpa/resources-glassfish/WEB-INF/classes/GlassfishDerbyDialect.class is a special hack to get around a Derby bug in Glassfish server. You must use it as your Hibernate dialect if you use Derby with Glassfish.

seam-gen is a very useful tool for developers to quickly get an application up and running, and provides a foundation to add your own functionality. Out of box seam-gen will produce applications configured to run on JBoss AS. These instructions will show the steps needed to get it to run on Glassfish. As stated above in Section 39.2, “ The jee5/booking example ” there is easy to deploy on glassfish either EJB3 or Seam POJOs based application

The first step is setting up seam-gen to construct the base project. There are several choices made below, specifically the datasource and hibernate values that we will adjust once the project is created.

				./seam setup
				Buildfile: build.xml

				init:

				setup:
				[echo] Welcome to seam-gen :-)
				[input] Enter your Java project workspace (the directory that contains your
				Seam projects) [C:/Projects] [C:/Projects]
				/home/mnovotny/projects
				[input] Enter your JBoss home directory [C:/Program Files/jboss-4.2.3.GA]
				[C:/Program Files/jboss-4.2.3.GA]

				[input] Enter the project name [myproject] [myproject]
				seamgen_example
				[echo] Accepted project name as: seamgen_example
				[input] Do you want to use ICEfaces instead of RichFaces [n] (y, [n])

				[input] skipping input as property icefaces.home.new has already
				been set.
				[input] Select a RichFaces skin [blueSky] ([blueSky], classic, ruby, wine,
				deepMarine, emeraldTown, japanCherry, DEFAULT)

				[input] Is this project deployed as an EAR (with EJB components) or a WAR
				(with no EJB support) [ear] ([ear], war)

				[input] Enter the Java package name for your session beans
				[com.mydomain.seamgen_example] [com.mydomain.seamgen_example]
				org.jboss.seam.tutorial.glassfish.action
				[input] Enter the Java package name for your entity beans
				[org.jboss.seam.tutorial.glassfish.action]
				[org.jboss.seam.tutorial.glassfish.action]
				org.jboss.seam.tutorial.glassfish.model
				[input] Enter the Java package name for your test cases
				[org.jboss.seam.tutorial.glassfish.action.test]
				[org.jboss.seam.tutorial.glassfish.action.test]
				org.jboss.seam.tutorial.glassfish.test
				[input] What kind of database are you using? [hsql] ([hsql], mysql, oracle,
				postgres, mssql, db2, sybase, enterprisedb, h2)

				[input] Enter the Hibernate dialect for your database
				[org.hibernate.dialect.HSQLDialect]
				[org.hibernate.dialect.HSQLDialect]

				[input] Enter the filesystem path to the JDBC driver jar
				[../lib/hsqldb.jar] [../lib/hsqldb.jar]

				[input] Enter JDBC driver class for your database [org.hsqldb.jdbcDriver]
				[org.hsqldb.jdbcDriver]

				[input] Enter the JDBC URL for your database [jdbc:hsqldb:.]
				[jdbc:hsqldb:.]

				[input] Enter database username [sa] [sa]

				[input] Enter database password [] []

				[input] Enter the database schema name (it is OK to leave this blank) [] []

				[input] Enter the database catalog name (it is OK to leave this
				blank) [] []

				[input] Are you working with tables that already exist in the database? [n]
				(y, [n])

				[input] Do you want to drop and recreate the database tables and data in
				import.sql each time you deploy? [n] (y, [n])

				[propertyfile] Creating new property file:
				/home/mnovotny/workspaces/jboss/jboss-seam/seam-gen/build.properties
				[echo] Installing JDBC driver jar to JBoss server
				[copy] Copying 1 file to
				/home/mnovotny/workspaces/jboss/jboss-seam/seam-gen/C:/Program
				Files/jboss-4.2.3.GA/server/default/lib
				[echo] Type 'seam create-project' to create the new project

				BUILD SUCCESSFUL
				Total time: 4 minutes 5 seconds

Type ./seam new-project to create your project and cd /home/mnovotny/projects/seamgen_example to the newly created structure.

We now need to make some changes to the generated project.

resources/META-INF/persistence-dev.xml
resources/GlassfishDerbyDialect.class

As with other examples we need to include this class for DB support. It can be copied from the jpa example into the seamgen_example/resources directory.

cp $SEAM_DIST/examples/jpa/resources-glassfish/WEB-INF/classes/GlassfishDerbyDialect.class
   ./resources
resources/META-INF/jboss-app.xml

You can delete this file as we aren't deploying to JBoss AS ( jboss-app.xml is used to enable classloading isolation in JBoss AS)

resources/*-ds.xml

You can delete these file as we aren't deploying to JBoss AS (these files define data sources in JBoss AS, we are using Glassfish's default data source)

resources/WEB-INF/components.xml
  • Enable container managed transaction integration - add the <transaction:ejb-transaction /> component, and it's namespace declaration xmlns:transaction="http://jboss.com/products/seam/transaction"

  • Alter the jndi-pattern to java:comp/env/seamgen_example/#{ejbName}/local

resources/WEB-INF/web.xml

As with the jee5/booking example we need to add EJB references to the web.xml. These references require the empty local-home to flag them for Glassfish to perform the proper binding.



  <ejb-local-ref>              
    <ejb-ref-name>seamgen_example/AuthenticatorAction</ejb-ref-name>                
    <ejb-ref-type>Session</ejb-ref-type>     
    <local-home></local-home>
    <local>org.jboss.seam.tutorial.glassfish.action.Authenticator</local>  
  </ejb-local-ref>
   
  <ejb-local-ref>
    <ejb-ref-name>seamgen_example/EjbSynchronizations</ejb-ref-name>  
    <ejb-ref-type>Session</ejb-ref-type>
    <local-home></local-home>
    <local>org.jboss.seam.transaction.LocalEjbSynchronizations</local>
  </ejb-local-ref>

This application has similar requirements as the jee5/booking example.