让 Tomcat 7 按固定顺序部署 Web 工程(独立 Context 配置文件方式)

一、背景

为什么要固定部署顺序呢?

由于目前的工程越来越复杂,Web 工程间也存在依赖关系。如果存在 a,b,c 三个工程(同 Tomcat),a 启动时需要访问 b,c 的 RESTful 接口才可以正常部署(a 启动时要访问某些业务)。这时就有出现部署顺序的问题。

Tomcat 7 中默认是不支持自定义独立 Context 配置文件部署顺序的。

二、分析

通过分析 Tomcat 源码,可以发现就是采用 File.list 方法来获得子文件的,不同操作系统无法确定顺序,也无法指定顺序。

见 org.apache.catalina.startup.HostConfig#deployApps()

protected void deployApps() {

        File appBase = appBase();
        File configBase = configBase();
        String[] filteredAppPaths = filterAppPaths(appBase.list());
        // Deploy XML descriptors from configBase
        deployDescriptors(configBase, configBase.list());  //注意这行,就只使用了 File.list 方法获取子来文件
        // Deploy WARs
        deployWARs(appBase, filteredAppPaths);
        // Deploy expanded folders
        deployDirectories(appBase, filteredAppPaths);

    }

我是否可以重写 HostConfig 来达到我的目的呢?在研究扩展的同时也研究如何让 Tomcat 识别我改写的 HostConfig。

最终我发现可以修改 server.xml 配置文件来加载我改写的 HostConfig 类,从而实现了部署顺序的自定义。(hostConfigClass 属性)


            
        

三、实现程序

1、样例项目结构

让 Tomcat 7 按固定顺序部署 Web 工程(独立 Context 配置文件方式)_第1张图片

context-deploy-order 为主功能程序(jar),context-parent 为父 POM,context-tomcat-dist 为打 zip 样例包工程,context-web-a/b/c 为模拟 Web 应该。

a 应用中定义了一个 Listener,启动时访问 b,c 应用的页面并取值。

2、POM 文件

pom.xml(context-parent)



    4.0.0

    org.noahx.tomcat
    context-parent
    pom
    1.0.0-SNAPSHOT

    
        ../context-deploy-order
        ../context-web-a
        ../context-web-b
        ../context-web-c
        ../context-tomcat-dist
    

    
        7.0.59
    

    
        

            
                org.apache.tomcat
                tomcat-catalina
                ${tomcat.version}
            

            
                org.apache.tomcat
                tomcat
                ${tomcat.version}
                zip
            

        
    

pom.xml(context-deploy-order)


    4.0.0

    
        org.noahx.tomcat
        context-parent
        1.0.0-SNAPSHOT
        ../context-parent/pom.xml
    

    context-deploy-order

    
        
            org.apache.tomcat
            tomcat-catalina
            provided
        
    

3、主功能程序(org.noahx.tomcat.ContextDeployOrderHostConfig)

该程序会从 context-deploy-order.properties 读取部署顺序。

package org.noahx.tomcat;

import org.apache.catalina.startup.HostConfig;
import org.apache.catalina.util.ContextName;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created by noah on 3/16/15.
 */
public class ContextDeployOrderHostConfig extends HostConfig {

    /**
     * context 启动顺序属性配置文件
     */
    public static final String DEPLOY_ORDER_PROP = "/context-deploy-order.properties";
    private static final Log log = LogFactory.getLog(ContextDeployOrderHostConfig.class);
    /**
     * 排序文件名列表
     */
    private List orderFiles = new ArrayList();
    /**
     * 排序属性
     */
    private Properties orderProperties = new Properties();

    /**
     * 加载顺序属性文件
     */
    private void loadOrderProperties() {
        InputStream resourceAsStream = this.getClass().getResourceAsStream(DEPLOY_ORDER_PROP);
        if (resourceAsStream != null) {
            try {
                orderProperties.load(resourceAsStream);
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            } finally {
                try {
                    resourceAsStream.close();
                } catch (IOException e) {
                    log.error(e.getMessage(), e);
                }
            }
        }
    }

    /**
     * 转为数组
     *
     * @return
     */
    private String[] orderFilesToArray() {
        String[] result = new String[orderFiles.size()];

        for (int c = 0; c < result.length; c++) {
            result[c] = orderFiles.get(c).getFilename();
        }

        return result;
    }

    /**
     * 获取文件名排序号
     *
     * @param filename
     * @return
     */
    private int getFileOrder(String filename) {
        String property = orderProperties.getProperty(filename, "100"); //如果没有,默认100
        return Integer.valueOf(property);
    }

    @Override
    protected void deployDescriptors(final File configBase, String[] files) {

        if (files != null && files.length > 0) { //不为空时,处理顺序

            ExecutorService startStopExecutor = host.getStartStopExecutor(); //检查启动停止线程池的最大值,如果大于1,输出warn日志(说明为多线程启动不保证启动依赖)
            if (startStopExecutor instanceof ThreadPoolExecutor) {
                ThreadPoolExecutor executor = (ThreadPoolExecutor) startStopExecutor;
                if (executor.getMaximumPoolSize() > 1) {
                    log.warn("host.getStartStopExecutor() MaximumPoolSize=" + executor.getMaximumPoolSize());
                }
            }

            loadOrderProperties(); //加载属性文件

            orderFiles.clear(); //清除排序文件名列表

            for (String filename : files) {
                OrderFile orderFile = new OrderFile();
                orderFile.setFilename(filename);
                orderFile.setOrder(getFileOrder(filename));

                orderFiles.add(orderFile);
            }

            Collections.sort(orderFiles); //排序

            if (log.isInfoEnabled()) {
                for (OrderFile orderFile : orderFiles) {
                    log.info(">>Context Deploy>> '" + orderFile.getFilename() + "' Order:" + orderFile.getOrder());
                }

            }

            final String[] strings = orderFilesToArray();

            //#1 Thread 方式
            new Thread() { //!!!为了先让端口启动需要单独跑一个线程,保证 StartStopExecutor 就不会被占用
                @Override
                public void run() {//从org.apache.catalina.startup.HostConfig.deployDescriptors()中提取并修改的代码
                    for (int i = 0; i < strings.length; i++) {
                        File contextXml = new File(configBase, strings[i]);

                        if (strings[i].toLowerCase(Locale.ENGLISH).endsWith(".xml")) {
                            ContextName cn = new ContextName(strings[i], true);

                            if (isServiced(cn.getName()) || deploymentExists(cn.getName()))
                                continue;
                            deployDescriptor(cn, contextXml);
                        }
                    }
                }
            }.start();

            //#2 直调方式
            //super.deployDescriptors(configBase, strings); //如果不访问其它 context 的 HTTP 服务,没有必要使用 Thread 方式

        } else { //空,加载原有方法
            super.deployDescriptors(configBase, files);
        }
    }

    /**
     * 文件名排序 Bean,实现排序
     */
    private static class OrderFile implements Comparable {
        private String filename;
        private int order;

        public String getFilename() {
            return filename;
        }

        public void setFilename(String filename) {
            this.filename = filename;
        }

        public int getOrder() {
            return order;
        }

        public void setOrder(int order) {
            this.order = order;
        }

        @Override
        public int compareTo(OrderFile o) {
            return Integer.compare(this.order, o.getOrder());
        }
    }
}
注:Tomcat 7 使用  StartStopExecutor 线程池控制启动执行,默认是1, 所以是串行。但这样会有个问题,如果要在部署过程中访问 HTTP 服务(本样例需要),端口必须先行启动。所以实现程序中使用了 Thread 将部署过程独立开,与 Tomcat  正常启动并行进行。

4、context-deploy-order.properties(-dist 工程中 src/install/misc/conf/context-deploy-order.properties)

b.xml=1
c.xml=2
a.xml=3

5、server.xml(-dist 工程中 src/install/misc/conf/server.xml)

只需要增加 hostConfigClass 属性




    

    
        

        

        
            
        

    

6、Web a 中的 Listener(调用 b,c 中 HTTP 内容)

package org.noahx.tomcat.web.a;


import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.impl.SimpleLogger;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * Created by noah on 3/17/15.
 */
public class StartupListener implements ServletContextListener {

    static {
        System.setProperty(SimpleLogger.DEFAULT_LOG_LEVEL_KEY, "INFO");
    }

    public static final String BASE_URL = "http://127.0.0.1:8080";
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        int b = getPingValue("/b/ping.jsp"); //ping.jsp 内容 123
        int c = getPingValue("/c/ping.jsp"); //ping.jsp 内容 235

        if (b != -1 && c != -1) { //访问依赖 web 成功
            logger.info(">>>  b={} c={} OK.", b, c);
        } else {//访问依赖 web 失败
            logger.error(">>>  b={} c={} ERROR!", b, c);
        }

    }

    /**
     * 获得 ping.jsp 页面中的 int 值
     *
     * @param urlStr
     * @return
     */
    private int getPingValue(String urlStr) {
        int result = -1; //失败 -1
        try {
            URL url = new URL(BASE_URL + urlStr);
            HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setConnectTimeout(10000); //10s 连接超时
            urlConnection.setReadTimeout(10000); //10s 读取超时
            urlConnection.connect();

            if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { //服务正常
                InputStream inputStream = null;
                try {
                    inputStream = urlConnection.getInputStream();
                    String s = IOUtils.toString(inputStream, "UTF-8").trim();
                    result = Integer.valueOf(s);
                } finally {
                    IOUtils.closeQuietly(inputStream);
                }
            }

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}

四、打样例包

在 context-parent 目录中执行,mvn clean package,会生成 context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT.zip 文件。
ZIP 文件中有 tomcat1,tomcat2 两个 tomcat 配置。两 Tomcat 的 context 配置文件全在 conf/Catalina/localhost/ 目录下。

tomcat1 是采用上文提供的程序与配置来固定 a,b,c 部署顺序的。conf/server.xml 被替换,在 lib 中增加了 context-deploy-order-1.0.0-SNAPSHOT.jar 与 context-deploy-order.properties。其它与 tomcat2 并无差异。

tomcat2 是原生 Tomcat 没有做任何处理。

五、效果

tomcat1 部署成功,tomcat2 部署失败

1、tomcat1(成功)

Mar 17, 2015 12:44:08 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host} Setting property 'hostConfigClass' to 'org.noahx.tomcat.ContextDeployOrderHostConfig' did not find a matching property.
Mar 17, 2015 12:44:08 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Mar 17, 2015 12:44:08 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 720 ms
Mar 17, 2015 12:44:08 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 17, 2015 12:44:08 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.59
Mar 17, 2015 12:44:08 PM org.noahx.tomcat.ContextDeployOrderHostConfig deployDescriptors
INFO: >>Context Deploy>> 'b.xml' Order:1
Mar 17, 2015 12:44:08 PM org.noahx.tomcat.ContextDeployOrderHostConfig deployDescriptors
INFO: >>Context Deploy>> 'c.xml' Order:2
Mar 17, 2015 12:44:08 PM org.noahx.tomcat.ContextDeployOrderHostConfig deployDescriptors
INFO: >>Context Deploy>> 'a.xml' Order:3
Mar 17, 2015 12:44:08 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/conf/Catalina/localhost/b.xml
Mar 17, 2015 12:44:09 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/webapps/manager
Mar 17, 2015 12:44:09 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/webapps/manager has finished in 875 ms
Mar 17, 2015 12:44:09 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deployment of configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/conf/Catalina/localhost/b.xml has finished in 887 ms
Mar 17, 2015 12:44:09 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/webapps/docs
Mar 17, 2015 12:44:09 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/conf/Catalina/localhost/c.xml
Mar 17, 2015 12:44:10 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deployment of configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/conf/Catalina/localhost/c.xml has finished in 161 ms
Mar 17, 2015 12:44:10 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/conf/Catalina/localhost/a.xml
Mar 17, 2015 12:44:10 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/webapps/docs has finished in 210 ms
Mar 17, 2015 12:44:10 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/webapps/host-manager
Mar 17, 2015 12:44:10 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/webapps/host-manager has finished in 277 ms
Mar 17, 2015 12:44:10 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/webapps/ROOT
Mar 17, 2015 12:44:10 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/webapps/ROOT has finished in 70 ms
Mar 17, 2015 12:44:10 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/webapps/examples
Mar 17, 2015 12:44:10 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/webapps/examples has finished in 457 ms
Mar 17, 2015 12:44:10 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Mar 17, 2015 12:44:10 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 2082 ms [Thread-2] INFO org.noahx.tomcat.web.a.StartupListener - >>>  b=123 c=235 OK.
Mar 17, 2015 12:44:11 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deployment of configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat1/conf/Catalina/localhost/a.xml has finished in 1,224 ms

INFO org.noahx.tomcat.web.a.StartupListener - >>>  b=123 c=235 OK.

2、tomcat2(失败)

Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/7.0.59
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Jan 28 2015 15:51:10 UTC
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         7.0.59.0
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Linux
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            3.13.0-37-generic
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             /opt/Noah/JDKs/jdk1.8.0_31/jre
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_31-b13
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.util.logging.config.file=/opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/conf/logging.properties
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/endorsed
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.io.tmpdir=/opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/temp
Mar 17, 2015 12:46:05 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Mar 17, 2015 12:46:05 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Mar 17, 2015 12:46:05 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1177 ms
Mar 17, 2015 12:46:05 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 17, 2015 12:46:05 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.59
Mar 17, 2015 12:46:05 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/conf/Catalina/localhost/a.xml
java.net.SocketTimeoutException: Read timed out
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.read(SocketInputStream.java:150)
	at java.net.SocketInputStream.read(SocketInputStream.java:121)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
	at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
	at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:703)
	at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1535)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
	at org.noahx.tomcat.web.a.StartupListener.getPingValue(StartupListener.java:52)
	at org.noahx.tomcat.web.a.StartupListener.contextInitialized(StartupListener.java:32)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5524)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:672)
	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1859)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
java.net.SocketTimeoutException: Read timed out
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.read(SocketInputStream.java:150)
	at java.net.SocketInputStream.read(SocketInputStream.java:121)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
	at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
	at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:703)
	at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1535)
	at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
	at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
	at org.noahx.tomcat.web.a.StartupListener.getPingValue(StartupListener.java:52)
	at org.noahx.tomcat.web.a.StartupListener.contextInitialized(StartupListener.java:33)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5524)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:672)
	at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1859)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
[localhost-startStop-1] ERROR org.noahx.tomcat.web.a.StartupListener - >>>  b=-1 c=-1 ERROR!
Mar 17, 2015 12:46:16 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deployment of configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/conf/Catalina/localhost/a.xml has finished in 10,721 ms
Mar 17, 2015 12:46:16 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/conf/Catalina/localhost/b.xml
Mar 17, 2015 12:46:16 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deployment of configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/conf/Catalina/localhost/b.xml has finished in 139 ms
Mar 17, 2015 12:46:16 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/conf/Catalina/localhost/c.xml
Mar 17, 2015 12:46:16 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deployment of configuration descriptor /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/conf/Catalina/localhost/c.xml has finished in 132 ms
Mar 17, 2015 12:46:16 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/webapps/manager
Mar 17, 2015 12:46:17 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/webapps/manager has finished in 110 ms
Mar 17, 2015 12:46:17 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/webapps/docs
Mar 17, 2015 12:46:17 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/webapps/docs has finished in 51 ms
Mar 17, 2015 12:46:17 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/webapps/host-manager
Mar 17, 2015 12:46:17 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/webapps/host-manager has finished in 55 ms
Mar 17, 2015 12:46:17 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/webapps/ROOT
Mar 17, 2015 12:46:17 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/webapps/ROOT has finished in 47 ms
Mar 17, 2015 12:46:17 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/webapps/examples
Mar 17, 2015 12:46:17 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory /opt/Noah/IdeaProjects/context-deploy-order/context-tomcat-dist/target/context-tomcat-dist-1.0.0-SNAPSHOT/tomcat2/webapps/examples has finished in 455 ms
Mar 17, 2015 12:46:17 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Mar 17, 2015 12:46:17 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Mar 17, 2015 12:46:17 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 11887 ms

ERROR org.noahx.tomcat.web.a.StartupListener - >>>  b=-1 c=-1 ERROR!

六、源码下载

附件:https://onedrive.live.com/redir?resid=55DC3C0254F15CFF%21160

转载于:https://my.oschina.net/noahxiao/blog/387884

你可能感兴趣的:(让 Tomcat 7 按固定顺序部署 Web 工程(独立 Context 配置文件方式))