Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the workflow for application startup and configuration when using Apache TomEE

I understand that Apache TomEE is a regular Tomcat installation with openejb as a web app.

I am trying to understand how all this bootstraps. I will try and ask a few directed questions:

  • Is it important to have an application startup order ? Should openejb start before my web app, or the other way round, or does it not matter ?
  • Related to the earlier question. How does an enterprise application register it's beans with openejb, or is it that openejb goes around hunting for enterprise applications in the same server, for EJB's ?
  • At a very layman level, how were they able to provide openejb as the EJB container, when it is a different web app. (IIRC every webapp in Tomcat gets a different classpath and they cannot step on each other's toes)

Any other important information.

like image 425
Parag Avatar asked Apr 18 '12 08:04

Parag


1 Answers

The integration is bootstrapped via this line in the conf/server.xml:

<Listener className="org.apache.tomee.loader.OpenEJBListener" />

This happens immediately at startup before any applications are started. The libraries from the <tomcat-home>/webapps/openejb/lib directory are added to the Tomcat system classloader, another listener is installed to participate in deployment and from then on out everything happens using events in the Tomcat lifecycle. Tomcat will issue several events at application startup (deploy) and shutdown. Tomcat itself uses them for deployment of servlets and essentially the integration is just more of the same. Other vendors that include Tomcat also use these hooks. From that perspective the integration is really quite boring :)

The only interesting twist is putting the extra libraries in a war file. That's really only done to make delivering the and adding the extra libraries to an existing Tomcat install as easy as possible (and as easy as possible to remove). All the libraries from <tomcat-home>/webapps/openejb/lib could just as easily go right in <tomcat-home>/lib. At which point, the only thing you might want the webapss/openejb/ war for is to be able to invoke EJBs over HTTP.

So the short answers are:

  • Appliction startup order doesn't matter
  • EJB Deployment happens side-by-side with Servlet deployment
  • Jars are added to the Tomcat system classloader immediately on Tomcat itself starts up

Interesting thing to note in the other answer is that Tomcat actually starts up with only two jars in the classpath. Tomcat itself actually adds all the jars from <tomcat-home>/lib/ automatically at startup. We're basically doing the same thing, just from <tomcat-home>/webapps/openejb/lib

I don't think we've actually tested moving the libraries into <tomcat-home>/lib/ and deleting the openejb webapp (which is called tomee.war in the coming final release), but I'll make a note to try that. Seems like a good thing to support or maybe even do by default. You can delete the Tomcat manager and ROOT webapps, so it seems like a good idea to make it easy to delete the openejb.war as well.

like image 184
David Blevins Avatar answered Oct 15 '22 02:10

David Blevins