How to control webapp deployment order when restarting tomcat

前端 未结 5 847
终归单人心
终归单人心 2020-12-20 03:09

I have a number of war projects deployed in a single tomcat 5.5 container. They consume each other\'s services through http, and thus I need to make sure that, when Tomcat

5条回答
  •  猫巷女王i
    2020-12-20 04:01

    It is true that tomcat does not provide any way to enforce deployment order.

    Tomcat deploys webapps in following order:

    1.Any Context Descriptors will be deployed first.

    2.Exploded web applications not referenced by any Context Descriptor will then be deployed. If they have an associated .WAR file in the appBase and it is newer than the exploded web application, the exploded directory will be removed and the webapp will be redeployed from the .WAR

    3.WAR files will be deployed

    Here is a proposed solution:

    If you want to specify the deployment order then define a context for your web app in $CATALINA_BASE/conf/[enginename]/[hostname]/MyApp.xml

    Tomcat scans $CATALINA_BASE/conf/[enginename]/[hostname]/ by performing File listFiles() which returns a File array sorted by hash value (OS dependent).

    You may use the following code to check in which order webapps will be deployed

    File file = new File("/opt/tomcat/conf/Catalina/localhost");
            File[] files = file.listFiles();
            for (File f : files)
            {
                System.out.println("Filename: " + f.getName());
            }
    

    Naming deployment descriptor appropriately will solve your problem.

提交回复
热议问题