public void process(String args[]) {
setCatalinaHome(); //设定Home与Base的值为user.dir
setCatalinaBase();
if (arguments(args)) //省略try catch
execute(); //检查args的格式
}
protected void execute() throws Exception {
if (starting)
start();
else if (stopping)
stop();
} 我们主要看如何启动。 protected void start() { //省略了大量非核心代码 及try catch
...
// Create and execute our Digester
Digester digester = createStartDigester(); //这个要是不懂看15章
File file = configFile(); //指定文件为conf/server.xml
InputSource is =new InputSource("file://" + file.getAbsolutePath());
FileInputStream fis = new FileInputStream(file);
is.setByteStream(fis);
digester.push(this); //把catalina自己放了进去
//catalina里有server组件
digester.parse(is);
fis.close();
...
// Start the new server
if (server instanceof Lifecycle) {
server.initialize();
// Wait for the server to be told to shut down
server.await(); //上面的英文再给大家解释一下吧
//除非收到SHUTDOWM的指令 就一直阻塞在这里
//这要是不懂 回去看第二三章
}
...
// Shut down the server
if (server instanceof Lifecycle) {
((Lifecycle) server).stop();
}
} protected Digester createStartDigester() {
// Initialize the digester
Digester digester = new Digester();
if (debug)
digester.setDebug(999);
digester.setValidating(false);
// Configure the actions we will be using
digester.addObjectCreate("Server",
"org.apache.catalina.core.StandardServer",
"className");
digester.addSetProperties("Server");
//解释一下下面
//在解析server.xml时 如果碰到Server这个模式
//就调用栈底元素的方法名为setServer参数为org.apache.catalina.Server的方法
//把Server自己(就是上面addObjectCreate产生的那个)注入栈底的那个元素
//那么栈底是什么呢?
//digester.push(this); 看看这行代码还有Catalian的setServer方法
digester.addSetNext("Server",
"setServer",
"org.apache.catalina.Server");
.....
return digester
} public static void main(String args[]) {// 省略非核心代码及try catch
// Construct the class loaders we will need
ClassLoader commonLoader = null;
ClassLoader catalinaLoader = null;
ClassLoader sharedLoader = null;
...
// Load our startup class and call its process() method
// Instantiate a startup class instance
if (debug >= 1)
log("Loading startup class");
Class startupClass =
catalinaLoader.loadClass
("org.apache.catalina.startup.Catalina");
Object startupInstance = startupClass.newInstance(); //加载Catalina类
// Call the process() method
if (debug >= 1)
log("Calling startup class process() method");
methodName = "process";
paramTypes = new Class[1];
paramTypes[0] = args.getClass();
paramValues = new Object[1];
paramValues[0] = args;
method =
startupInstance.getClass().getMethod(methodName, paramTypes);
method.invoke(startupInstance, paramValues); //调用Catalina的process方法
}
关于startup.bat的知识,我们下一节再谈... 哎还有一节呀
How tomcat works 读书笔记十七 启动tomcat 上
原文:http://blog.csdn.net/dlf123321/article/details/41966739