Joshua Java

Deploying Seam POJO apps on Glassfish

Posted on: January 29, 2008

Alot of people wondered whether Seam can be deployed on other appserver other than JBoss AS. Well indeed it can. Now I’m going to show how to deploy Seam on Glassfish in a very simple way without you having to modify your project stub that is created with seam-gen. So in the future you only have to modify your persistence.xml, other than that you can deploy the same seam apps you deploy on JBossAS. Note that this only works with Seam POJO apps and doesn’t work with Seam EJB3 apps mainly because Glassfish requires you to write the EJB3 reference on your web.xml. So it’s not Seam fault! As this blog entry is written I am using Seam 2.x and Glassfish 2.

Here’s what you need to do:

  1. Copy these libraries into $GLASSFISH_HOME/domains/$DOMAIN_NAME/lib/ext:
    • javassist
    • dom4j
    • hibernate-validator
    • commons-logging
    • cglib-nodep
    • eclipse-jdt-core. In seam distribution this is packaged as core.jar πŸ™‚
    • antlr
    • log4j
    • Your database JDBC driver. I use mysql, so I would copy mysql-connector-java here
  2. Copy these libraries into $GLASSFISH_HOME/lib: Here we will use Hibernate as the persistence layer and will override toplink which is the default persistence layer from Glassfish because Seam does not yet support Toplink as the persistence layer for Seam POJO apps.
    • jboss-archive-browsing
    • jboss-common-core
    • hibernate core. The core library
    • hibernate-annotations
    • hibernate-commons-annotations
    • hibernate-entitymanager
    • hibernate-validator
  3. Note: These libraries is bundled with seam distribution so you don’t have download it separately.
    FAQ: We copied these libraries into two different folders because Glassfish has a very unique classloader and becaus we want to override Toplink which is located inside $GLASSFISH_HOME/lib

  4. Create your connection pool and datasource from Glassfish admin console. Create it from these menu from inside of your admin console:
    • Resources > JDBC > Connection Pools
    • Resources > JDBC > JDBC Resources
  5. Open up your persistence.xml. If your project is created with seam-gen this will be located inside $PROJECT_HOME/resources/META-INF/. And then edit these lines:
    • element into the datasource you’ve created on previous step
    • hibernate.dialect property into the database you use. You can find these dialects for various databases inside hibernate docs.
    • hibernate.transaction.manager_lookup_class into org.hibernate.transaction.SunONETransactionManagerLookup

Now the next time you create and deploy another project to the same Glassfish server, you only need to do step 3 and 4. Good luck πŸ™‚


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Flickr Photos

%d bloggers like this: