javatomcattomcat7tomcat6maven-tomcat-plugin

Restarting embedded tomcat


I use the embedded tomcat via the maven-tomcat-plugin. In version 6 of that plugin, if i do mvn tomcat6:run, the server starts and the contextInitialized methods execute BEFORE the connector tries to open the port.

No change in code but when I start with mvn tomcat7:run the server opens the ports and THEN tries to start the contextInitialized methods.

Why?

I'm asking because I used the context initialized to find a running tomcat and kill it so that the new instance can take its port. If tomcat fails taking the ports and then checks the contextInitialized methods that doesn't work anymore. Is there another way to redeploy an embedded tomcat without having downtimes?


Solution

  • In tc6 we had the problem that the contextInitialized-methode requires informations about the connector, for example if https and mutual-authentications is used and what users are registred in tomcat-users.xml.

    Unfortunately theese informations where not available at context-initialization and requests who are incomming before the users-list has been loaded (but after context-init) where rejected.

    Thats why we changed this in tc7.

    You are using multiple tomcats for some reason (idc), and the solution should better be on a higher level.

    My suggestion: Replace the HTTP-Connector by a AJP-Connector on both tomcats using different ports, install Apache's httpd and switch the tomcats by reload httpd-config.

    AJP details.