April 3, 2009

TOTD # 77: Running Seam examples with GlassFish

Seam is a full-stack solution to assemble complex web applications using simple annotated classes, a rich set of UI components, and very little XML. It integrates Ajax and Business Process Modeling with several Java EE technologies such as Java Server Faces (JSF), Java Persistence API (JPA), and Enterprise Java Beans (EJB 3.0).

GlassFish is a Java EE compliant application server so it’s natural to pick GlassFish as your deployment platform for Seam applications :)

This blog is going to show how Seam samples can be easily run on GlassFish.

  1. Download Seam 2.1.1 GA from here and unzip.
  2. Build “examples/jpa” sample as:
    ~/tools/jboss-seam-2.1.1.GA/examples/jpa >ant glassfish
    Buildfile: build.xml

    glassfish:

    initcopy:

    initpoms:
         [echo] Setting up dependencies
        [mkdir] Created dir: /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms
         [copy] Copying 1 file to /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms
    [artifact:install] [INFO] Installing /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms/root.pom to . . .

    . . .

    init.war:

    war:
         [copy] Copying 27 files to /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/exploded-archives-glassfish/jboss-seam-jpa.war
         [copy] Copying 7 files to /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/exploded-archives-glassfish/jboss-seam-jpa.war/WEB-INF/lib

    noejb.war:
         [copy] Copying 18 files to /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/exploded-archives-glassfish/jboss-seam-jpa.war/WEB-INF/lib
         [copy] Copying 2 files to /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/exploded-archives-glassfish/jboss-seam-jpa.war
         [copy] Copying 4 files to /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/exploded-archives-glassfish/jboss-seam-jpa.war

    distributable.war:

    noejb.archive:
          [jar] Building jar: /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jpa/dist-glassfish/jboss-seam-jpa.war

    BUILD SUCCESSFUL
    Total time: 5 seconds

  3. Deploy the sample as:
    ~/tools/jboss-seam-2.1.1.GA/examples/jpa >~/tools/glassfish/v2.1/glassfish/bin/asadmin deploy dist-glassfish/jboss-seam-jpa.war
    Command deploy executed successfully.

    The app is now accessible at “http://localhost:8080/jboss-seam-jpa” and here are some of the captured screenshots:

    Simple and easy!

  4. Build “examples/hibernate” as:
    ~/tools/jboss-seam-2.1.1.GA/examples/hibernate >ant glassfish
    Buildfile: build.xml

    glassfish:

    initcopy:

    initpoms:
         [echo] Setting up dependencies
         [copy] Copying 1 file to /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms
    [artifact:install] [INFO] Installing /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms/root.pom to /Users/arungupta/.m2/repository/org/jboss/seam/root/2.1.1.GA/root-2.1.1.GA.pom

     . . .

    distributable.war:

    noejb.archive:
          [jar] Building jar: /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/hibernate/dist-glassfish/jboss-seam-hibernate.war

    BUILD SUCCESSFUL
    Total time: 6 seconds

  5. Deploy the sample as:
    ~/tools/jboss-seam-2.1.1.GA/examples/hibernate >~/tools/glassfish/v2.1/glassfish/bin/asadmin deploy dist-glassfish/jboss-seam-hibernate.war
    Command deploy executed successfully.

    The app is now accessible at “http://localhost:8080/jboss-seam-hibernate” and has exactly similar snapshots as shown in “jboss-seam-jpa” sample. Simple and easy, yet again!

  6. Build “examples/jee5/booking” and deploy as:
    ~/tools/jboss-seam-2.1.1.GA/examples/jee5/booking >ant
    Buildfile: build.xml

    initcopy:

    initpoms:
         [echo] Setting up dependencies
         [copy] Copying 1 file to /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms
    [artifact:install] [INFO] Installing /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms/root.pom to /Users/arungupta/.m2/repository/org/jboss/seam/root/2.1.1.GA/root-2.1.1.GA.pom
         [copy] Copying 1 file to /Users/arungupta/tools/jboss-seam-2.1.1.GA/classes/poms

    . . .

    archive:
          [jar] Building jar: /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jee5/booking/dist/jboss-seam-jee5-booking.jar
          [jar] Building jar: /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jee5/booking/dist/jboss-seam-jee5-booking.war
          [jar] Building jar: /Users/arungupta/tools/jboss-seam-2.1.1.GA/examples/jee5/booking/dist/jboss-seam-jee5-booking.ear

    BUILD SUCCESSFUL
    Total time: 5 seconds
    ~/tools/jboss-seam-2.1.1.GA/examples/jee5/booking >~/tools/glassfi
    sh/v2.1/glassfish/bin/asadmin deploy dist/jboss-seam-jee5-booking.ear

    Command deploy executed successfully.

    The application is now accessible at “http://localhost:8080/seam-jee5-booking”. Wow, that’s simple and easy as well!

So we have deployed multiple Seam samples on GlassFish v2.1 – simple and easy!

Here are some more useful pointers realted to Seam and GlassFish:

  • Chapter 39 of the Seam Community Documentation even describes how to deploy an application created using seam-gen on GlassFish.
  • Dan Allen, the author of Manning’s Seam in Action, presented a webinar at TheAquarium Online.
  • Several other Seam entries @ TA.
  • Deploying a seam-gen project to GlassFish (blog entry) – Here is a quote from the blog:

    GlassFish has a very sexy administrative console, but it also has a very sexy commandline tool known as asadmin. The asadmin tool gives you virtually unbounded control over the application server, including core tasks such as starting and stopping the application server, deploying and undeploying applications, and setting up database connection pools, amidst a plethora of other controls. You’ll see that my modified seam-gen tool takes advantage of a handful of these commands.

    And another one …

    GlassFish gives you efficiency through automation, which is undoubtedly the most effective way to become efficient. … GlassFish volunteers itself to participate in a script and is the reason why I choose it as my preferred application server.

  • GlassFish support added to seam-gen: It is certainly exciting to know that there are targets like “gf-deploy-datasource”, “gf-deploy-hibernate”, and “gf-prepare” available to Seam developers out-of-the-box.
  • Sample Application using JSF, Seam, and Java Persistence APIs on GlassFish – detailed step-by-step blog explaining how to run Seam applications on GlassFish

The other samples in the bundle (that I tried) rely upon non-Java EE jars in the App Server’s classpath. A slight build file tweaking can bundle those jars in the application itself and will allow to run them as well.

Are you deploying your Seam applications on GlassFish ?

Happy Seaming on GlassFish!

Please leave suggestions on other TOTD (Tip Of The Day) that you’d like to see. A complete archive of all the tips is available here.

Technorati: totd seam glassfish javaee javaserverfaces ejb jpa

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. TOTD# 86: Getting Started with Apache Wicket on GlassFish
  2. TOTD #75: Getting Started with Grails using GlassFish v3 Embedded
  3. TOTD #18: How to Build The GlassFish v3 Gem for JRuby ?
  4. TOTD #31: CRUD Application using Grails – Hosted on GlassFish and MySQL
  5. TOTD #103: GlassFish v3 with different OSGi runtimes – Felix, Equinox, and Knoplerfish

6 Comments »

  1. Sun’s just been bought out by IBM and the general consensus is that NetBeans is probably going to be dropped like a stone…as you’re arguably one of the experts on GlassFish, how is the merger going to affect this project as well? I cannot in any confidence recommend any Sun technology in the workplace with the company in limbo.

    Comment by eru — April 3, 2009 @ 4:47 pm

  2. eru, Our company policy is to not comment on rumors.

    Comment by Arun Gupta — April 3, 2009 @ 8:20 pm

  3. Do you happen to have a maven version of this? We wanted to move our Seam application from JBoss to Glassfish but had too many problems with dependencies and classpaths. Also the great embedded maven glassfish plugin really helps people getting started. It’d be nice to try this out simply by unzipping and typing "mvn glassfish:run."

    Comment by Steven B — April 10, 2009 @ 9:47 am

  4. Steven, good thought! I’m traveling next week so will try a maven version after I come back.

    Comment by Arun Gupta — April 10, 2009 @ 9:55 am

  5. thank you

    Comment by neon — April 26, 2009 @ 2:16 pm

  6. thank you

    Comment by neon tabela — April 26, 2009 @ 2:16 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress
101911 visits from Sep 11, 2009