2

I have three general JavaEE + Tomcat questions:

  1. According to this link (Using Hibernate with Tomcat) running Hibernate in Tomcat is possible (despite Tomcat not supporting JPA). Does anyone know if I'll run into problems with this configuration (Hibernate on Tomcat)?

  2. Can I do something similar to get EJB3.1 support in Tomcat? For example, by dropping the correct files into WEB-INF/lib and WEB-INF/classes could I run EJB3.1 in a standard Tomcat7 container (not TomEE)? If yes, which EJB3.1 providers are recommended?

  3. Generally, is it possible to run any JavaEE technology from within Tomcat as long as the appropriate libraries and configuration files are placed in WEB-INF/lib and WEB-INF/classes? Or, is it only possible to run the technologies for which Tomcat supports the interfaces?

Thanks in advance for all help!

Alex Averbuch
  • 3,245
  • 5
  • 33
  • 44
  • What is it about TomEE that would make you want to avoid it and build your own Java EE functionality on Tomcat? I don't mean that in a challenging way, more looking for feedback. We could easily build different flavors of Tomcat + friends if there was something specific you had in mind. – David Blevins May 12 '12 at 23:19
  • Mostly because I'm new to the JavaEE/JavaWeb world and I want to understand what I do (remove the magic). If I can achieve the same thing by just adding dependencies to Maven (like with JSF, JAX-RS, etc.) that would give me more control – Alex Averbuch May 14 '12 at 08:28
  • Because TomEE adds implementations of most/all JavaEE standards, what would happen if I wanted to use something else, e.g. by providing a different JSF implementation via Maven? Would TomEE still use MyFaces, or would it automatically use my provided Majorra libraries? – Alex Averbuch May 14 '12 at 08:29
  • 1
    This is a good start on the removing the magic front: http://stackoverflow.com/questions/269186/besides-ear-and-ejb-what-do-i-get-from-a-j2ee-app-server-that-i-dont-get-in-a/9199893#9199893 – David Blevins May 14 '12 at 19:58
  • 2
    On the note of swapping out parts, some of that is possible because they were designed to be replaced at the specification level (JPA for example). Others are a practical impossibility (EJB). JSF is one of those "in the middle" parts. Properly integrated, JSF should support Java EE injection, transactions, container-managed EntityManagers, CDI @ConversationScoped and a few more. – David Blevins May 14 '12 at 20:10
  • Ultimately, the best way to remove the magic is to become an app server developer. Rather than doing that alone, you could join up with like-minded people. We always love having new people to help develop TomEE and I'm sure plenty of people would love more choice in componentry. – David Blevins May 14 '12 at 20:26
  • @DavidBlevins, thanks a lot for the link to that other question. After reading it I have two concerns with using TomEE. *(1)* What happens if I want to change the version of MyFaces (or other library)? Is that trivial to achieve? *(2)* I really want to use Hibernate, particularly for Hibernate Search. Can I use Hibernate instead of OpenJPA while still keeping all the container managed benefits? – Alex Averbuch May 14 '12 at 21:28
  • 2
    1. Changing minor versions of MyFaces is easy, changing to another JSF impl would be hard. 2. Many TomEE users use Hibernate instead of OpenJPA. Just drop Hibernate into tomcat/lib/ and add `org.hibernate.ejb.HibernatePersistence` in your `persistence.xml` file – David Blevins May 14 '12 at 21:44
  • This is still very much relevant for an old post. Building up your base Tomcat using Maven dependencies to build your own flavor of JEE (7?) is very appealing. I went that route, and was able to [add in CDI and JSF](http://musingsinjava.wordpress.com/2014/11/02/enabling-jsf-2-2-and-cdi-1-2-on-tomcat-8/) support quite easily. However EJB and JPA support seemed more challenging, definitely when you want full container support (like using the `@PersistenceContext` annotation). At times it seemed a choice of either choosing TomEE with just JEE 6 support, or later JSF/CDI with limited EJB/JPA. – YoYo Nov 14 '14 at 07:26

3 Answers3

3
  1. No problems - it's very common.
  2. Yes. For example OpenEJB is the predecessor to TomEE. Per the downloads page (below).
  3. No.

Drop-in WARs.

A version of Apache OpenEJB that can be dropped into any Tomcat 7.x install effectively creating your own Apache TomEE Web Profile or Apache TomEE Plus.

sourcedelica
  • 23,940
  • 7
  • 66
  • 74
0
  1. You won't run into problems, but you'll have to handle transactions and session handling yourself, unless you use Spring for example.

  2. No.

  3. No.

Tomcat is a servlet and JSP container, and not a full-stack Java EE container. A Java EE container must support EAR files, and Tomcat only deploys WAR files. Stuffing libraries into a WAR file won't make it an EAR file.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Thank you. Could you briefly clarify (by editing the answer) what it is that prevents Tomcat from being able to support EJB please? – Alex Averbuch May 11 '12 at 21:42
  • Thanks again. Two more things. **1** Is it the inability to support EAR files that prevents Tomcat from supporting EJB3.1? **2** What is it about JPA & JAX-RS (vs EJB) that makes it possible to add support for them in Tomcat? – Alex Averbuch May 11 '12 at 21:58
  • 2
    The JPA spec defines two kinds of entity managers: container-managed entity managers and application-managed entity managers. JPA can be used in any environment, and doesn't need a JEE container. Don't know for JAX-RS, but since it's an API for web services, it makes sense to be able to use it inside a web container. Tomcat could support EJB3.1. You could name such a thing TomEE or JBoss. – JB Nizet May 11 '12 at 22:07
0

Many things that are in Java EE can be added to Tomcat. TomEE is the living proof of that. What TomEE does is mostly what you can also do.

It's really typical to add JPA (Hibernate) and a JTA transaction manager (Atomikos, JoTM, etc) to Tomcat. Next on the list is JSF (Mojarra or MyFaces) and CDI (Weld). JAX-RS (Jersey, RestEasy) can also be added.

At the end you could ask yourself if it isn't easier to just install TomEE or GlassFish though...

Mike Braun
  • 3,729
  • 17
  • 15
  • As above... I'm new to the JavaEE/JavaWeb world and want to understand what I do. If I can achieve the same thing by just adding dependencies to Maven (like with JSF, JAX-RS, etc.) that would give me more control. Also, because TomEE adds implementations of most/all JavaEE standards, what would happen if I wanted to use something else, e.g. provide a different JSF implementation via Maven? Would TomEE still use MyFaces, or would it automatically use my provided Majorra libraries from WEB-INF/lib? – Alex Averbuch May 14 '12 at 08:45
  • In general you can not just override functionality that's already there in your war. Compare this to eg packaging your own String class to override the JDK's one. Follow the specific procedure of the AS you're using. – Mike Braun May 18 '12 at 08:20