Is there a way to enforce a deployment order in tomcat6?

wleao picture wleao · Jul 14, 2011 · Viewed 22.4k times · Source

I have 3 wars in my webapp folder. Two of them are built on services of the third one. I'm in a testing environment, i.e. I don't have control over their architectures, so I'm no able to change a thing. So...

Question: Is there a way to enforce a deployment order in tomcat?

I've ran into one question here in stackoverflow, but there's no solution.

Well, actually the guy suggests that changing the name of the webapps to an alphabetical order would help. However, I'm not willing to do that everytime I need to test those and different wars.

I'm positive that there's a way of doing that configuring one of the tomcat conf .xml files. I just don't know which one.

Answer

user177800 picture user177800 · Jul 14, 2011

From the Tomcat Wiki - What order do webapps start (or How can I change startup order)?

There is no expected startup order. Neither the Servlet spec nor Tomcat define one. You can't rely on the apps starting in any particular order.

Tomcat has never supported specifying load order of webapps. There are other containers like JBoss that do, but Tomcat never has. Any apparent behavior that looks like load ordering via the alphabetical order of the names of the web apps is coincidental and not guaranteed to work in all cases.

What you are probably thinking of is the <load-on-startup/> element if the web.xml that specifies order of loading servlets.

That said there is an elegant solution using a service discovery protocol.

One solution is to use something like ZeroConf and register your services when they start up, and then have the dependent apps look for when these services come available and have them connect and do what ever they need to do when the service is ready. This is how I have been handling multiple dependent services for years now. I have Python, Java and Erlang services all discovering each other via ZeroConf seemlessly.