Help

The Seam 2.1.0.SP1 release included a new reference guide chapter describing Seam integration with GlassFish v2. As with most container integration the bulk of the work is reconciling library differences, datasources and deployment descriptor changes. Glassfish is no different in that regard, however it is much easier to integrate and work with GlassFish than some of the other containers that I written about.

To demonstrate the ease of integration with GlassFish I'll show you how to deploy 2 different Seam examples, and migrate a seam-gen application one in one blog - and it won't even be that long - well not too long ;-)

GlasshFish Version and Setup

For this blog I used GlassFish v2ur4-b04 on a linux machine with JDK6. The instructions for installing GlassFish are at the bottom of the download page and are pretty straightforward. I'll assume that you have it installed and have created a domain as explained on the download page.

Note: all of the examples below require the embedded javaDB database that ships with GlassFish to be started. To start and stop the database execute:

$ asadmin start-database
$ asadmin stop-database

The jee5/booking Example

This example is based on the Seam Booking example and showcases how to build Java EE 5 compliant Seam application. To build and deploy it follow these steps.

  1. Navigate to the $SEAM_HOME/examples/jee5/booking directory
  2. Execute ant
  3. The example will build the ear file into the $SEAM_HOME/examples/jee5/booking/dist directory.
  4. Use the GlassFish Admin Console to deploy jboss-seam-jee5.ear as an Enterprise Application with all the default settings.
  5. Navigate to http://localhost:8080/seam-jee5/ and check out the example.

Thats it, nothing else is needed.

The jpa Example

This is the Hotel Booking example implemented with Seam POJOs and Hibernate JPA. Building and deploying this example is nearly the same as the jee5/booking example.

  1. Navigate to the $SEAM_HOME/examples/jpa directory
  2. Execute ant glassfish
  3. The example will build the war file into the $SEAM_HOME/examples/jpa/dist-glassfish directory.
  4. Use the GlassFish Admin Console to deploy jboss-seam-jpa.war as a Web Application with all the default settings.
  5. Navigate to http://localhost:8080/jboss-seam-jpa/ and check out the example.

These examples were quite easy and straightforward to build and deploy. This is partially because they were built with GlassFish integration in mind. You might be asking what actual changes are needed to deploy to GlassFish. The next section will cover that exact thing.

Migrating a seam-gen Project to GlassFish

The Seam framework uses seam-gen as a tool for developers to quickly get an application up and running, and provides a foundation to add your own functionality. seam-gen creates applications that deploy to JBoss AS. This section will detail what to change so you can deploy into GlassFish.

Initial Project Setup

First step is to get seam-gen to setup and create the base project. In the $SEAM_HOME directory execute ./seam setup. This will launch a command line questionnaire about your application. Set the JBoss home and workspace as you wish. Set the project name to seamgen_example, use RichFaces ( instead of IceFaces ), and we want to make an ear project. For all the other entries you can use the default values.

Then have seam-gen create the project by executing ./seam new-project. Then navigate to the new project for the rest of the steps.

Configuration File Changes

Below are the various changes needed to the default configuration files.

resources/META-INF/persistence-dev.xml

  • Change the jta-data-source to be jdbc/__default
  • Replace all of the persistence properties with the following:
<property name="hibernate.dialect" value="GlassFishDerbyDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/>

resources/GlassFishDerbyDialect.class

We need to copy this file from the jpa example to work around an issue with Derby (javaDB) packaged with GlassFish. From the seamgen_example project base execute the following.

cp $SEAM_HOME/examples/jpa/resources-glassfish/WEB-INF/classes/GlassFishDerbyDialect.class ./resources

resources/WEB-INF/components.xml

  • We want GlassFish to manage our transactions so we need to add <transaction:ejb-transaction /> and its namespace xmlns:transaction="http://jboss.com/products/seam/transaction" at the top of the file.
  • Change the jndi-pattern to java:comp/env/seamgen_example/#{ejbName}

resources/WEB-INF/web.xml

We need to add the following to the bottom of web.xml so that GlassFish binds the EJBs correctly.

  <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>

resources/META-INF/application.xml

Our base application does not have any of its own EJBs yet, and GlassFish does not like it when an application declares an EJB module that contains no EJBs. So we need to remove the following:

 <module>
    <ejb>seamgen_example.jar</ejb>
 </module>

Updating the Build File

Now all that is left is updating the build.xml file for the seamgen_example project.

Adding GlassFishDerbyDialect.class to the Build

To do this locate the jar target and add the <include name="GlassFishDerbyDialect.class" /> where it is show below.

 <target name="jar" depends="compile,copyclasses" description="Build the distribution .jar file">
   <copy todir="${jar.dir}">
      <fileset dir="${basedir}/resources">
         <include name="seam.properties" />
         <include name="*.drl" />
         <include name="GlassFishDerbyDialect.class" />
      </fileset> 
   </copy>
  ...

Adding Dependent Libraries

Locate the ear target and add the following <include .../> elements into the <copy todir="${ear.dir}/lib"> so that the <fileset dir="${lib.dir}"> looks like this:

 <fileset dir="${lib.dir}">
   <includesfile name="deployed-jars-ear.list" />
   
   <!-- Hibernate and deps -->
   <include name="hibernate.jar"/>
   <include name="hibernate-commons-annotations.jar"/>
   <include name="hibernate-annotations.jar"/>
   <include name="hibernate-entitymanager.jar"/>
   <include name="hibernate-validator.jar"/>
   <include name="jboss-common-core.jar" />
   
   <!-- 3rd party and supporting jars -->
   <include name="javassist.jar" />
   <include name="dom4j.jar" />
   <include name="concurrent.jar" />
   <include name="cglib.jar" />
   <include name="asm.jar" />
   <include name="antlr.jar" />
   <include name="commons-logging.jar" />
   <include name="commons-collections.jar" />
 </fileset>

Build and Deploy

All that is left at this point is to build and deploy the application.

To build it all you have to do is run ant archive in the seamgen_example directory. This will create a seamgen_example/dist directory with the seamgen_example.ear file in it.

Deploy this example the same way we deployed the jee5/booking example.

Check out the fruits of your labor at http://localhost:8080/seamgen_example.

Wrap up

So this blog was a little longer than expected but we did deploy 3 applications not just 1 like the other interoperability blogs ;-) These should give you a good starting point for your Seam own applications on GlassFish.

For more details on installing GlassFish, and some of changes we made please see the Seam on GlassFish application server reference guide chapter.

Update: Some changes and fix's were recently made to the reference guide chapter. This blog contains the latest information, and updates will be in the 2.1.1.CR1 release of seam.

5 comments:
20. Feb 2009, 03:47 CET | Link
Bernard Adjei | bennyadjei(AT)yahoo.com

+ am using seam 2.0.0.GA and i get the following errors after following ur procedure in deploying my app to glassfish v2(component of netbeans 6.0). The error appears in netbeans' output console but no error in seen on the glassfish admin interface. I also get a redirect loop message on my firefox browser when i to acces my app at localhost:8080/seamgenExample Initializing Sun's JavaServer Faces implementation (1.2_04-b20-p03) for context '/seamgenExample' Welcome to Seam null scanning: /C:/Program%20Files/glassfish-v2/domains/domain1/applications/j2ee-apps/seamgenExample/seamgenExample_war/WEB-INF/lib/jboss-seam-ui.jar could not read entries java.io.FileNotFoundException: C:\ProgramFiles\glassfish-v2\domains\domain1\applications\j2ee-apps\seamgenExample\seamgenExample_war\WEB-INF\lib\jboss-seam-ui.jar (The system cannot find the path specified) at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.<init>(ZipFile.java:114) at java.util.zip.ZipFile.<init>(ZipFile.java:131) at org.jboss.seam.deployment.Scanner.handleArchive(Scanner.java:151) at org.jboss.seam.deployment.Scanner.scan(Scanner.java:132) at org.jboss.seam.deployment.NamespaceScanner.getPackages(NamespaceScanner.java:39) at org.jboss.seam.init.Initialization.addNamespaces(Initialization.java:783) at org.jboss.seam.init.Initialization.create(Initialization.java:85) at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:34) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4515) at org.apache.catalina.core.StandardContext.start(StandardContext.java:5176) at com.sun.enterprise.web.WebModule.start(WebModule.java:327) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:973) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:957) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:688) at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1581) at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1222) at com.sun.enterprise.web.WebContainer.loadJ2EEApplicationWebModules(WebContainer.java:1147) at com.sun.enterprise.server.TomcatApplicationLoader.doLoad(TomcatApplicationLoader.java:141) at com.sun.enterprise.server.AbstractLoader.load(AbstractLoader.java:244) at com.sun.enterprise.server.ApplicationManager.applicationDeployed(ApplicationManager.java:336) at com.sun.enterprise.server.ApplicationManager.applicationDeployed(ApplicationManager.java:210) at com.sun.enterprise.server.ApplicationManager.applicationDeployed(ApplicationManager.java:645) at com.sun.enterprise.admin.event.AdminEventMulticaster.invokeApplicationDeployEventListener(AdminEventMulticaster.java:928) at com.sun.enterprise.admin.event.AdminEventMulticaster.handleApplicationDeployEvent(AdminEventMulticaster.java:912) at com.sun.enterprise.admin.event.AdminEventMulticaster.processEvent(AdminEventMulticaster.java:461) at com.sun.enterprise.admin.event.AdminEventMulticaster.multicastEvent(AdminEventMulticaster.java:176) at com.sun.enterprise.admin.server.core.DeploymentNotificationHelper.multicastEvent(DeploymentNotificationHelper.java:308) at com.sun.enterprise.deployment.phasing.DeploymentServiceUtils.multicastEvent(DeploymentServiceUtils.java:226) at com.sun.enterprise.deployment.phasing.ServerDeploymentTarget.sendStartEvent(ServerDeploymentTarget.java:298) at com.sun.enterprise.deployment.phasing.ApplicationStartPhase.runPhase(ApplicationStartPhase.java:132) at com.sun.enterprise.deployment.phasing.DeploymentPhase.executePhase(DeploymentPhase.java:108) at com.sun.enterprise.deployment.phasing.PEDeploymentService.executePhases(PEDeploymentService.java:919) at com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeploymentService.java:591) at com.sun.enterprise.deployment.phasing.PEDeploymentService.start(PEDeploymentService.java:635) at com.sun.enterprise.admin.mbeans.ApplicationsConfigMBean.start(ApplicationsConfigMBean.java:744) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:375) at com.sun.enterprise.admin.MBeanHelper.invokeOperationInBean(MBeanHelper.java:358) at com.sun.enterprise.admin.config.BaseConfigMBean.invoke(BaseConfigMBean.java:464) at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:836) at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:761) at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.sun.enterprise.admin.util.proxy.ProxyClass.invoke(ProxyClass.java:90) at $Proxy1.invoke(Unknown Source) at com.sun.enterprise.admin.server.core.jmx.SunoneInterceptor.invoke(SunoneInterceptor.java:304) at com.sun.enterprise.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:174) at com.sun.enterprise.deployment.client.DeploymentClientUtils.startApplication(DeploymentClientUtils.java:145) at com.sun.enterprise.deployment.client.DeployAction.run(DeployAction.java:537) at java.lang.Thread.run(Thread.java:619) scanning: C:\Program Files\glassfish-v2\domains\domain1\applications\j2ee-apps\seamgenExample\jboss-seam_jar scanning: /C:/Program Files/glassfish-v2/domains/domain1/applications/j2ee-apps/seamgenExample/seamgenExample_war/WEB-INF/lib/jboss-seam-ui.jar scanning: /C:/Program Files/glassfish-v2/domains/domain1/applications/j2ee-apps/seamgenExample/seamgenExample_war/WEB-INF/lib/jboss-seam-ioc.jar scanning: /C:/Program%20Files/glassfish-v2/domains/domain1/applications/j2ee-apps/seamgenExample/seamgenExample_war/WEB-INF/lib/jboss-seam-ioc.jar could not read entries java.io.FileNotFoundException: C:\Program%20Files\glassfish-v2\domains\domain1\applications\j2ee-apps\seamgenExample\seamgenExample_war\WEB-INF\lib\jboss-seam-ioc.jar (The system cannot find the path specified) at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.<init>(ZipFile.java:114) at java.util.zip.ZipFile.<init>(ZipFile.java:131) at org.jboss.seam.deployment.Scanner.handleArchive(Scanner.java:151) at org.jboss.seam.deployment.Scanner.scan(Scanner.java:132)

ReplyQuote
 
20. Jun 2009, 01:44 CET | Link

Any specific IDE can be used for working out this example steps????

23. Jun 2014, 10:38 CET | Link

This site is a leading resource for information about the Igor Ledochowski Power Of Conversational Hypnosis PDF book and hypnotic training system that teaches you effective techniques for influencing and persuading people to give you exactly what you want during everyday conversations.https://www.rebelmouse.com/powerofconversationalhypnosis/

27. Jun 2014, 12:00 CET | Link

The Vert Shock system is compatible with desktop and laptop computers, iPhones, iPads, and virtually any tablet, smart phone, or other device that has PDF and video viewing capabilities.https://www.rebelmouse.com/folkersystemvertshockreviews/

23. Sep 2014, 06:35 CET | Link
jassica

This handy article dissects the major techniques associated with decorative concrete, including staining, coloring, stamping, scoring, and sealing, and gives many advantages of each. It also compares decorative concrete methods to other flooring options like tile, wood, etc. Concrete Coatings

Post Comment