X

TOTD # 77: Running Seam examples with GlassFish

Guest Author
cellspacing="2">
href="http://docs.jboss.com/seam/latest/reference/en-US/html/Book-Preface.html"> style="border: 0px solid ; width: 353px; height: 125px;" alt=""
src="">
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 href="http://sourceforge.net/project/showfiles.php?group_id=22866&package_id=163777&release_id=647861">here
    and unzip.
  2. Build "examples/jpa" sample as:

    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">~/tools/jboss-seam-2.1.1.GA/examples/jpa > style="font-weight: bold;">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:

    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">~/tools/jboss-seam-2.1.1.GA/examples/jpa > style="font-weight: bold;">~/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:

    href="//cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/f4a5b21d-66fa-4885-92bf-c4e81c06d916/Image/d0a893f51c2924e585165eb85ac36397/seam211_gf2_1_jpa_login_screen.png"> style="border: 2px solid ; width: 700px; height: 606px;" alt=""
    src="//cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/f4a5b21d-66fa-4885-92bf-c4e81c06d916/Image/d0a893f51c2924e585165eb85ac36397/seam211_gf2_1_jpa_login_screen.png">

    href="//cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/f4a5b21d-66fa-4885-92bf-c4e81c06d916/Image/6f400cbc77b2e6330182505d8c986d81/seam211_gf2_1_jpa_hotels_list.png"> style="border: 2px solid ; width: 700px; height: 613px;" alt=""
    src="//cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/f4a5b21d-66fa-4885-92bf-c4e81c06d916/Image/6f400cbc77b2e6330182505d8c986d81/seam211_gf2_1_jpa_hotels_list.png">

    href="//cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/f4a5b21d-66fa-4885-92bf-c4e81c06d916/Image/0a49aa44b5c50a74b33f22f0b637ff10/seam211_gf2_1_jpa_hotel_details.png"> style="border: 2px solid ; width: 700px; height: 580px;" alt=""
    src="//cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/f4a5b21d-66fa-4885-92bf-c4e81c06d916/Image/0a49aa44b5c50a74b33f22f0b637ff10/seam211_gf2_1_jpa_hotel_details.png">


    Simple and easy!
  4. Build "examples/hibernate" as:

    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">~/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:

    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">~/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:

    style="text-align: left; background-color: rgb(204, 204, 255); width: 100%;"
    cellpadding="2" cellspacing="2">~/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 > style="font-weight: bold;">~/tools/glassfish/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:
  • href="http://docs.jboss.org/seam/latest/reference/en-US/html/glassfish.html">Chapter
    39 of the href="http://docs.jboss.org/seam/latest/reference/en-US/html/index.html">Seam
    Community Documentation even describes how to deploy an
    application created using href="http://docs.jboss.org/seam/latest/reference/en-US/html/glassfish.html#d0e32240">seam-gen
    on GlassFish.
  • Dan Allen, the author of Manning's href="http://www.manning.com/dallen/">Seam in Action,
    presented a href="http://wikis.sun.com/display/TheAquarium/Seam+and+WebBeans">webinar
    at TheAquarium Online.
  • Several other href="http://blogs.sun.com/theaquarium/tags/seam">Seam
    entries @ TA.
  • href="http://code.google.com/p/seaminaction/wiki/DeployingToGlassFish">Deploying
    a seam-gen project to GlassFish ( href="http://www.mojavelinux.com/blog/archives/2008/10/deploying_a_seamgen_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.
  • href="http://in.relation.to/Bloggers/JBossAS5AndGlassFishSupportAddedToSeamgen">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.
  • href="http://weblogs.java.net/blog/caroljmcdonald/archive/2007/07/sample_applicat_1.html">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 href="http://blogs.sun.com/arungupta/tags/totd">here.




Technorati: totd
seam href="http://technorati.com/tags/glassfish">glassfish
javaee
javaserverfaces
ejb href="http://technorati.com/tags/jpa">jpa

Join the discussion

Comments ( 15 )
  • eru Friday, April 3, 2009

    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.


  • Arun Gupta Friday, April 3, 2009

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


  • Steven B Friday, April 10, 2009

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


  • Arun Gupta Friday, April 10, 2009

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


  • neon Sunday, April 26, 2009

    thank you


  • neon tabela Sunday, April 26, 2009

    thank you


  • Jason Sunday, October 4, 2009

    This example does not work on GlassFish :(


  • Arun Gupta Sunday, October 4, 2009

    Jason,

    Which GlassFish version ?

    Can you post more details to users@glassfish.dev.java.net ?


  • Jason Tuesday, October 6, 2009

    Hi Arun,

    thanks for reply. the email with more details subject: "Seam example does not work on GlassFish" was sent to users@glassfish.dev.java.net


  • Jason Tuesday, October 6, 2009

    Hi again!

    The email did sent, but I has received SPAM with offer:

    "To subscribe to the list, send a blank message to:

    users-subscribe@glassfish.dev.java.net"

    I did not want get spams!

    So more details I post here:

    I did try install Seam example (jboss-seam/examples/jee5/booking/) as

    at: http://blogs.sun.com/arungupta/entry/totd_77_running_seam_examples.

    But Seam example does not work on GlassFish.

    Crash while deploy:

    [#|2009-10-06T15:35:53.079+0400|SEVERE|glassfish|null|_ThreadID=33;_ThreadName=Thread-3;|log4j:WARN

    No appenders could be found for logger

    (javax.servlet.ServletContextListener).|#]

    [#|2009-10-06T15:35:53.080+0400|SEVERE|glassfish|null|_ThreadID=33;_ThreadName=Thread-3;|log4j:WARN

    Please initialize the log4j system properly.|#]

    [#|2009-10-06T15:35:53.716+0400|INFO|glassfish|javax.enterprise.system.core.classloading.com.sun.enterprise.loader|_ThreadID=33;_ThreadName=Thread-3;|org.jboss.seam.example.booking.User

    actually got transformed|#]

    [#|2009-10-06T15:35:56.561+0400|SEVERE|glassfish|org.apache.catalina.core.StandardContext|_ThreadID=33;_ThreadName=Thread-3;|PWC1306:

    Startup of context /seam-jee5-booking failed due to previous errors|#]

    ...

    ..

    Exception while loading the app : java.lang.Exception:

    java.lang.IllegalStateException: ContainerBase.addChild: start:

    org.apache.catalina.LifecycleException: java.lang.LinkageError: loader

    constraint violation: loader (instance of

    org/apache/felix/framework/ModuleImpl$ModuleClassLoader) previously

    initiated loading for a different type with name

    "javassist/bytecode/ClassFile"


  • Jason Tuesday, October 6, 2009

    My Info:

    glassfish-v3-preview-b66

    jboss-seam-2.2.0.GA


  • Arun Gupta Thursday, October 8, 2009

    Jason, I tried with GlassFish v2.1, haven't tried with v3 yet. Can you post your question to users@glassfish.dev.java.net ?


  • Arun Gupta Thursday, October 8, 2009

    Jason, I'll try with v3 in 2 weeks otherwise you can also post your question to the forum at:

    http://forums.java.net/jive/forum.jspa?forumID=56&start=0

    and stay away from clogging your inbox.


  • Markus Tuesday, December 29, 2009

    Hi Arun,

    have you tried to deploy the seambay example and tested if the webservices are running?

    The app itself was running very fast, but every times I try to use the webservice I get an:

    java.lang.IllegalStateException: No event context active

    Maybe you have an idea (the seam SOAPRequestHandler is called)?

    Markus


  • Arun Gupta Tuesday, January 5, 2010

    Markus, I've not tried seambay example. Can you post your question to users@glassfish.dev.java.net ?


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.