18

If I can choose, I use JBoss 7 for a Java EE 6 project using JSF 2 and CDI.

But sometimes, the environment for a customer's project is more or less set - so in one case we are limited to Tomcat (6 or maybe 7).

So, I read a couple of articles about using CDI (e.g. WELD) and JSF 2 within Tomcat, which showed that it's basically no problem doing it.

Still, my question is - does it make sense? Or is a servlet container just not the right environment for such an architecture? Has anyone any experience using Tomcat+CDI for something more than a demo project?

Thanks in advance!

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96
  • Would be great if you could update the question on how you finally decided... – Jan Groth Sep 05 '12 at 09:22
  • 1
    @jangroth As I said - my decision would be easy, but if the final decision is for Tomcat, I can live with it and a hundred jars in my war as long as there are no real blocking points aganinst Tomcat+CDI. – Alexander Rühl Sep 06 '12 at 11:46

2 Answers2

13

Good question, first of all :)

Deploying an enterprise application to a servlet engine is the main scenario of e.g. Spring, so it is certainly possible. But you will know that Spring is a whole ecosystem of APIs and config-files rather than a few JARs that you simply put on the server and have fun with.

I played quite a bit with Weld & JSF on Tomcat 7, and it worked pretty good. But there is a major difference between HelloWorldOnTomcat.java and a real application for real customers. I'm sure that you are aware of this.

I'd say that you will be able to compile a decent setup in relative short time. Neither CDI nor JSF will be problematic. But depending on your concrete requirements you then will have to deal with other aspects that are not covered by an out-of-the-box Tomcat. Security, clustering, fail-over, messaging, asynchronity to name a few concerns (And transactions, as mentioned in the comments).

If you are (more or less) proficient with such requirements and your upcoming project is rather relaxed and not supposed to control the next Mars mission - I'd certainly give it a try.

On the other hand if you know about such requirements I'd look for (a) a setup on a Java EE app server, or (b) another stack on a Tomcat.

Jan Groth
  • 14,039
  • 5
  • 40
  • 55
  • 5
    I will just add to the list of feature not covered by Tomcat + JSF and CDI, transaction management. If your application is no read only, you will probably need transaction and thus you will need to use an external framework for it (you can use spring for it) or do it your self. As JEE6 container are at least as light as Tomcat, try to push a bit JEE6 (TomEE can be a good start point ;) ) – Kazaag Aug 27 '12 at 16:27
4

Take a look at Apache Tomee:

Apache TomEE, pronounced "Tommy", is an all-Apache Java EE 6 Web Profile certified stack where Tomcat is top dog. Apache TomEE is assembled from a vanilla Apache Tomcat zip file. We start with Tomcat, add our jars and zip up the rest. The result is Tomcat with added EE features - TomEE.

Alberto Segura
  • 755
  • 1
  • 12
  • 28
  • 1
    I never used it, but heard of the project. It would indeed make sense, but the problem is as I said in my post that sometimes the environment is set at a customers site, so there's an Tomcat 7 installed and all we can do is deploy a WAR file. – Alexander Rühl Feb 19 '13 at 07:54
  • 1
    In that case, I think you should wrap all the components into the WAR file by yourself. Using Maven should help a lot. I don't recall if you'd have to tune any configuration in the container (Tomcat) for certain components. Anyway, taking a look at Apache TomEE website could help, as they achieved a fully functional integration of the JEE stack on an Apache Tomcat. – Alberto Segura Feb 19 '13 at 10:26