Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDI on Tomcat 7 - does it make sense?

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!

like image 397
Alexander Rühl Avatar asked Aug 27 '12 09:08

Alexander Rühl


2 Answers

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.

like image 39
Alberto Segura Avatar answered Oct 07 '22 02:10

Alberto Segura


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.

like image 122
Jan Groth Avatar answered Oct 07 '22 01:10

Jan Groth