Seam 2.0 and Tomcat

Darryl Smith pointed out that we can actually use non-JTA transactions with JPA in Tomcat now. So, I just added tomcat 5.5 and 6.0 build targets for the jpa example in CVS based on his suggestions.

In JBoss Seam 2.0, we made some changes to the way Tomcat is supported as a Seam runtime. It has caused some confusion. So, let me try to clarify here …

As you recall, in Seam 1.0 to 1.2, we can run Seam applications on Tomcat by bundling the JBoss Embeddable EJB3 library or the JBoss micro-container inside the WAR application. The application will need to bootstrap the EJB3 container or micro-container upon startup. However, the EJB3 library Jars is more than 20 MB. The idea of bootstraping the entire thing for each application is not very efficient. In Seam 2, we leverage the “Embeddable JBoss” library to provide shared EJB3 service to all WAR applications deployed in the Tomcat instance. You have two ways to run Seam 2 applications in Tomcat:

1. If you need to use EJB3 beans, you will need to install the “Embeddable JBoss” libraries as shared library in Tomcat. It is an easy process. You can find instructions for Tomcat 5.5 and 6.0 respectively. Once you do that, you can deploy Seam applications without any restrictions. You will be able to use full EJB3 features including session beans, entity beans, message driven beans, and web services etc.

Of course, you still cannot deploy EAR files on Tomcat. But you can bundle EJB3 JARs in the WEB-INF/lib directory of your WAR application — essentially re-creating the EAR structure in a WAR. Just run the tomcat.war ANT target on any of the official Seam examples to see how this is done.

2. If you absolutely cannot install any shared library or shared configuration on Tomcat, you can still run Seam applications. However, you will not be able to use EJB3 features — you must use Seam POJOs instead. You can, however, use JPA in local transaction mode. Seam manages the transaction manager and entity manager for you in this case.

Checkout the jpa and hibernate2 examples in Seam distribution and build for the tomcat55 or tomcat6 targets to see how this works. The jpa shows how to use JPA EntityManager with Seam POJOs and the hibernate2 example shows how to use Hibernate sessions with Seam POJOs. You will need to copy hsqldb.jar into Tomcat’s shared lib directory since the example app assumed that we will use a HSQL DB from JNDI (see META-INF/context.xml). Obviously, you do not have to do that in your own apps.

Okay, so much for Tomcat support. What about Seam 2 support for J2EE 1.4 application servers and non-JBoss Java EE 5 application servers? Here are the status:

  • J2EE 1.4 application servers: Try the jpa example in Seam distribution. It uses Seam POJOs to replace EJB3 session beans in other examples. The jpa example builds for JBoss 4.0.5/4.2.x, WebSphere 6.1.0.9, and WebLogic 9.2.
  • Java EE 5 application servers: Try the jee5 example in Seam distribution. It builds for JBoss AS 5.x, Glassfish V1/V2, and Oracle OC4J 11. We are currently working on WebLogic 10, which has some weird reflection issues.

Hope that helps!

27 Responses to “Seam 2.0 and Tomcat”

  1. kadoike Says:

    Hi,
    I read your seam book. That’s very good!!!
    And I always look forward to your blog.
    Now reading this entry, I have the questions.
    Please let me ask you a few questions.

    1. “We do not recommend that you run production Seam applications in plain Tomcat.” is described in your seam book.
    Does not this change in Seam2.0 and Tomcat either?

    2. If I have to run production Seam apps on Tomcat and Seam 2.0, which is realistic choice?
    (a)Seam EJB3(and POJO) + JPA (with Embeddable JBoss)
    (b)Seam POJO + JPA (without Embeddable JBoss)

    Thanks.

  2. Jason Wang Zhe Says:

    Hi,

    I am tring to make Seam 1.2.1 work with our WebLogic 9.2 and 10.0. However the download package only contains ant task for Tomcat. Is there any pointers I shall follow to use Seam on Weblogic 9.2/10 environment

    Thanks a million!

    Jason Wang

  3. Michael Yuan Says:

    kadoike,

    I’d really recommend you use Tomcat w/ Embeddable JBoss if possible. It gives you more features (e.g., EJB3 web services, remoting etc.). But more important, we test Seam much more frequently / extensively on the JBoss setup than on plain Tomcat.

    cheers
    Michael

  4. Michael Yuan Says:

    Jason,

    The JPA and Hibernate2 examples (examples/jpa and examples/hibernate2) have build targets for WebLogic 9.2. They use Seam POJOs instead of EJB3 session beans to manage the UI actions.

    We are not yet able to run Seam 2 on WebLogic 10.

    cheers
    Michael

  5. Seam4U Says:

    Hi Michael Yuan,
    I do have the same problem with Seam 1.2.1 GA JPA example on Weblogic 10. You can also see the post on SEAM forum:

    http://www.jboss.com/index.html?module=bb&op=viewtopic&t=113442

    I do posted on BEA forum but no reply yet.

    I think you’re taking care for SEAM to run on AS (other than Jboss). So, please help me.

    Thanks

  6. Stephen Friedrich Says:

    Is it really no longer possible to deploy the complete Embeddable JBoss as part of a single war?

    Our (very big) client has a policy of a single tomcat server per application anyway, but it would be close to impossible for use to change their policy regarding shared libraries.

  7. Simon Says:

    Hi Michael,
    developing a Seam 1.2 application on tomcat was a bit painful because of NullPointers in org.jboss.resource.connectionmanager.IdleRemover. I filed a bug report on this but it was not considered as a Seam issue. However, is this still an issue with Seam 2 and Tomcat?

    cheers
    Simon

  8. Brian Daley Says:

    Hello Michael,

    I am trying to get the hibernate2 example to run on WebSphere v6.1.0.9 without success. I have tried the 1.2.1GA and the 2.0.0.BETA1 seam downloads. I have seen several threads in the forums discussing successful deployment of hibernate2 to WAS v6.1.0.9. Is there someplace I can download a working copy of the hibernate2 application?

    Thanks,
    -Brian

  9. Michael Yuan Says:

    Stephen,

    No, single WAR deployment is no longer possible on Tomcat if you use EJB3 beans (JPA and Hibernate2 examples still run on a plain Tomcat as a single WAR).

    If your client allows you to customize the Tomcat instance for each app, then I guess installing the Embeddable JBoss on that Tomcat should not be an issue? Hope that works out for you …

    cheers
    Michael

  10. Michael Yuan Says:

    Brian,

    Please use the example from the CVS. We have not released a new beta since I made those changes. Thanks.

    cheers
    Michael

  11. Brian Daley Says:

    Michael,

    thanks for the quick response. Just to clarify, should I pull the example from CVS and run it on the 2.0.0.BETA1 Seam distro I already downloaded or do I need to pull all the code and build the Seam jars myself? I’m behind a firewall so getting anything from CVS is a pain.

    Thanks,
    -Brian

  12. Michael Yuan Says:

    Brian,

    I *think* you only need to check out the examples/hibernate2 directory.

    If you just want a working app to look at the config files etc., you can email me offline and I can just email you the WAR file.

    cheers
    Michael

  13. Matt Drees Says:

    Hi Michael,

    Regarding your statement: “…we leverage the “Embeddable JBoss” library to provide shared EJB3 service to all WAR applications deployed in the Tomcat instance.”

    This is true, but it’s worth noting that Embedded Jboss on tomcat doesn’t support multiple Seam apps.

    See Seam’s jira for details (http://jira.jboss.com/jira/browse/JBSEAM-1663).

  14. Tomas Says:

    Hi could you tell me the trick to run one application on tomcat :)

    I have tomcat 6.0.14, JBoss Embedded 2 Beta and seam 2
    so I copied files from Embedded to tomcat/lib also copied hbDB..jar
    then I modified server.xml and context.xml and added listeners according guide on JBoss, and it should be it, also I used java 5.

    I ran the server it was ok, but hitting application URL

    produces lot exceptions

    like SeamPhaceListener, Context, problem with transactions

    Thanks for help

    Tomas

  15. ip Says:

    Michael, Seam FAQ states:

    Q: Can I run Seam in a J2EE environment?
    A: Yes, as of Seam 1.1, you can use Seam in any J2EE application server, with one caveat: you will not be able to use EJB 3.0 session beans. However, you can use either Hibernate or JPA for persistence, and you can use Seam JavaBean components instead of session beans.

    My question related to this: is SEAM direction to make SEAM fully J2EE-compatible in the future, so it can run on any J2EE-compliant app server? If so, in which release?

    Thank you in advance for your help.

    IP

  16. imanlhakim Says:

    Seam is greate idea but it’s encapsulation often broken, I can easily use and play safety with Oracle ADF, RoR, PHP, and ASP.NET, not with seam. if I done some thing wrong like configuration mistake I got very long error message that did not related to my fault. IDE does not help at all. till now when I try to reverse engineer database always get hibernate error.

  17. UW Says:

    I am also very intereted to run Seam 2.0 in any J2EE-compatible App Server(for me: Jetty)

    Greetings

  18. Amit Tiwary Says:

    Hi Michael,
    I have started on Seam a few weeks and looks like it is going to be our framework for next set of web development. I was interested in hibernate2 example which came with Seam download. There were no unit/integration tests provided. Does it mean that we can’t have unit/integrated tests without embedded JBoss in Tomcat? Is there any way using which I will be able to write unit/integration tests in plain tomcat deployment scenario. Please help me with answers/suggestions to these queries as it is a big road block for me since last two days.
    Please help me.

    ps: I tried migrating the test cases from booking example here, but when I run ant test, it throws the below exception.

    testng] ERROR 05-11 18:51:49,517 [org.jboss.dependency.plugins.AbstractController.incrementState():456] Error installing to Start: name=jboss:database=localDB,service=Hypersonic state=Create mode=Manual requiredState=Installed
    [testng] java.sql.SQLException: Wrong database file version
    “.
    Mine is an Oracle Datasource configured in context.xml.

    Have a great day ahead.

    Thanks
    Amit

  19. Pablo Says:

    Hi Michel,
    I’ve enjoy working with seam and tomcat for a while now. I developed a few apps and seam really makes a difference when it comes to working with JSF.
    I decided it is time to upgrade to 2.0. I read some of the changes… I have to modify the tomcat install (really? hmmm, ok I can do that). I read some more and only one seam app per tomcat server… what? this kills me. I’m reading the forums and neither the seam team nor the embedded team take responsibility on this issue. Is there going to be a fix for this issue? Is running multiple seam apps in tomcat not going to be supported anymore? I hope Seam/Embedded Jboss reconsider this problem.

    Thanks
    Pablo

  20. Michael Yuan Says:

    Pablo,

    As of Seam 2.0, we no longer require JBoss Embeddable to run Seam applications on Tomcat. You have to use JPA POJOs and the RESOURCE_LOCAL transaction to run Seam on plain Tomcat. Please see the examples/jpa example, and build for tomcat55 / tomcat6.

    On the other hand, JBoss Embeddable is installed as a shared library on Tomcat. It does not prevent you from deploying multiple Seam apps on the same Tomcat instance. With JBoss Embeddable, you have access to EJB3 features and JTA transactions.

    cheers
    Michael

  21. Pablo Says:

    Michel,
    Thanks for your prompt response. I’m looking at running multiple seam apps in one embedded JBoss tomcat instance. However, I looked at this wiki page (the part where it says: “… Currently only one Seam application is supported per tomcat”). and this post on the embedded forum. Is this old documentation? (I hope it is so I can enjoy the new 301 features of seam 2) Maybe I’m missing something. I appreciate your help

    Thanks
    Pablo

  22. Michael Yuan Says:

    Pablo,

    I believe that you can run multiple Seam applications on the same tomcat instance — at least with RESOURCE_LOCAL transactions. Please try it and let us know. :)

    cheers
    Michael

  23. Techieexchange Says:

    Step-by-Step Tutorial: Seam2 (POJO+JPA)+Eclipse+Tomcat

    I wrote a step-by-step screencast tutorial to make Seam development as RAD - Rapid Application Development with Eclipse and Tomcat, focusing on developer productivity.

    http://techieexchange.wordpress.com/2007/11/11/rad-seam-development-with-eclipse-and-tomcat-step-by-step-tutorial-screencast

    I hope this tutorial will be useful for J2EE/JEE developers.

  24. Milan Says:

    Hi you all,

    I’m currently working on my graduate project
    (it’s about SEAM, and various ways of deploying SEAM apps)

    The question that’s been bothering me:

    Can I have a EJB3 application packed as a WAR file instead of EAR, but working that way on JBoss AS?

    I figured if you can have EJB3 WAR for tomcat why can’t you have a similar thing for JBoss?

    Thanks in advance,
    Milan

  25. Adrian Florea Says:

    Running the jpa example on Tomcat6 (maybe also Tomcat5) requires also to copy asm.jar in the server lib folder. Otherwise the example will not run because of a java.lang.NoClassDefFoundError: org/objectweb/asm/Type
    exceprion.

    Regards,
    Ady

    BTW: Is there a way to run Seam2 (EJB3) application in Tomcat without the need to change/enhance the server installation. Can the EJB3 Micro container be manually installed along with the custom war file?

  26. Johann Geyer Says:

    Hi Adrian!

    You are right concerning der asm.jar.

    With Seam2 it is not possible to deploy the microcontainer with the application war.

    Regards,
    Jo

  27. Xavier Says:

    Hi everybody,

    did somebody try to integrate a webservice functionality to the jpa example. The basic idea is to have tomcat+seam/jpa+ws (cxf, …).

    Regards,
    Xavier

Leave a Reply