001: /*
002: * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/startup/Bootstrap.java,v 1.36 2002/04/01 19:51:31 patrickl Exp $
003: * $Revision: 1.36 $
004: * $Date: 2002/04/01 19:51:31 $
005: *
006: * ====================================================================
007: *
008: * The Apache Software License, Version 1.1
009: *
010: * Copyright (c) 1999 The Apache Software Foundation. All rights
011: * reserved.
012: *
013: * Redistribution and use in source and binary forms, with or without
014: * modification, are permitted provided that the following conditions
015: * are met:
016: *
017: * 1. Redistributions of source code must retain the above copyright
018: * notice, this list of conditions and the following disclaimer.
019: *
020: * 2. Redistributions in binary form must reproduce the above copyright
021: * notice, this list of conditions and the following disclaimer in
022: * the documentation and/or other materials provided with the
023: * distribution.
024: *
025: * 3. The end-user documentation included with the redistribution, if
026: * any, must include the following acknowlegement:
027: * "This product includes software developed by the
028: * Apache Software Foundation (http://www.apache.org/)."
029: * Alternately, this acknowlegement may appear in the software itself,
030: * if and wherever such third-party acknowlegements normally appear.
031: *
032: * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
033: * Foundation" must not be used to endorse or promote products derived
034: * from this software without prior written permission. For written
035: * permission, please contact apache@apache.org.
036: *
037: * 5. Products derived from this software may not be called "Apache"
038: * nor may "Apache" appear in their names without prior written
039: * permission of the Apache Group.
040: *
041: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
042: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
043: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
044: * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
045: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
046: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
047: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
048: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
049: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
050: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
051: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
052: * SUCH DAMAGE.
053: * ====================================================================
054: *
055: * This software consists of voluntary contributions made by many
056: * individuals on behalf of the Apache Software Foundation. For more
057: * information on the Apache Software Foundation, please see
058: * <http://www.apache.org/>.
059: *
060: * [Additional notices, if required by prior licensing conditions]
061: *
062: */
063:
064: package org.apache.catalina.startup;
065:
066: import java.io.File;
067: import java.io.IOException;
068: import java.lang.reflect.Method;
069: import java.net.MalformedURLException;
070: import java.net.URL;
071: import java.util.ArrayList;
072: import org.apache.catalina.loader.Extension;
073: import org.apache.catalina.loader.StandardClassLoader;
074:
075: /**
076: * Boostrap loader for Catalina. This application constructs a class loader
077: * for use in loading the Catalina internal classes (by accumulating all of the
078: * JAR files found in the "server" directory under "catalina.home"), and
079: * starts the regular execution of the container. The purpose of this
080: * roundabout approach is to keep the Catalina internal classes (and any
081: * other classes they depend on, such as an XML parser) out of the system
082: * class path and therefore not visible to application level classes.
083: *
084: * @author Craig R. McClanahan
085: * @version $Revision: 1.36 $ $Date: 2002/04/01 19:51:31 $
086: */
087:
088: public final class Bootstrap {
089:
090: // ------------------------------------------------------- Static Variables
091:
092: /**
093: * Debugging detail level for processing the startup.
094: */
095: private static int debug = 0;
096:
097: // ----------------------------------------------------------- Main Program
098:
099: /**
100: * The main program for the bootstrap.
101: *
102: * @param args Command line arguments to be processed
103: */
104: public static void main(String args[]) {
105:
106: // Set the debug flag appropriately
107: for (int i = 0; i < args.length; i++) {
108: if ("-debug".equals(args[i]))
109: debug = 1;
110: }
111:
112: // Configure catalina.base from catalina.home if not yet set
113: if (System.getProperty("catalina.base") == null)
114: System.setProperty("catalina.base", getCatalinaHome());
115:
116: // Construct the class loaders we will need
117: ClassLoader commonLoader = null;
118: ClassLoader catalinaLoader = null;
119: ClassLoader sharedLoader = null;
120: try {
121:
122: File unpacked[] = new File[1];
123: File packed[] = new File[1];
124: File packed2[] = new File[2];
125: ClassLoaderFactory.setDebug(debug);
126:
127: unpacked[0] = new File(getCatalinaHome(), "common"
128: + File.separator + "classes");
129: packed2[0] = new File(getCatalinaHome(), "common"
130: + File.separator + "endorsed");
131: packed2[1] = new File(getCatalinaHome(), "common"
132: + File.separator + "lib");
133: commonLoader = ClassLoaderFactory.createClassLoader(
134: unpacked, packed2, null);
135:
136: unpacked[0] = new File(getCatalinaHome(), "server"
137: + File.separator + "classes");
138: packed[0] = new File(getCatalinaHome(), "server"
139: + File.separator + "lib");
140: catalinaLoader = ClassLoaderFactory.createClassLoader(
141: unpacked, packed, commonLoader);
142:
143: unpacked[0] = new File(getCatalinaBase(), "shared"
144: + File.separator + "classes");
145: packed[0] = new File(getCatalinaBase(), "shared"
146: + File.separator + "lib");
147: sharedLoader = ClassLoaderFactory.createClassLoader(
148: unpacked, packed, commonLoader);
149: } catch (Throwable t) {
150:
151: log("Class loader creation threw exception", t);
152: System.exit(1);
153:
154: }
155:
156: Thread.currentThread().setContextClassLoader(catalinaLoader);
157:
158: // Load our startup class and call its process() method
159: try {
160:
161: SecurityClassLoad.securityClassLoad(catalinaLoader);
162:
163: // Instantiate a startup class instance
164: if (debug >= 1)
165: log("Loading startup class");
166: Class startupClass = catalinaLoader
167: .loadClass("org.apache.catalina.startup.Catalina");
168: Object startupInstance = startupClass.newInstance();
169:
170: // Set the shared extensions class loader
171: if (debug >= 1)
172: log("Setting startup class properties");
173: String methodName = "setParentClassLoader";
174: Class paramTypes[] = new Class[1];
175: paramTypes[0] = Class.forName("java.lang.ClassLoader");
176: Object paramValues[] = new Object[1];
177: paramValues[0] = sharedLoader;
178: Method method = startupInstance.getClass().getMethod(
179: methodName, paramTypes);
180: method.invoke(startupInstance, paramValues);
181:
182: // Call the process() method
183: if (debug >= 1)
184: log("Calling startup class process() method");
185: methodName = "process";
186: paramTypes = new Class[1];
187: paramTypes[0] = args.getClass();
188: paramValues = new Object[1];
189: paramValues[0] = args;
190: method = startupInstance.getClass().getMethod(methodName,
191: paramTypes);
192: method.invoke(startupInstance, paramValues);
193:
194: } catch (Exception e) {
195: System.out.println("Exception during startup processing");
196: e.printStackTrace(System.out);
197: System.exit(2);
198: }
199:
200: }
201:
202: /**
203: * Get the value of the catalina.home environment variable.
204: */
205: private static String getCatalinaHome() {
206: return System.getProperty("catalina.home", System
207: .getProperty("user.dir"));
208: }
209:
210: /**
211: * Get the value of the catalina.base environment variable.
212: */
213: private static String getCatalinaBase() {
214: return System.getProperty("catalina.base", getCatalinaHome());
215: }
216:
217: /**
218: * Log a debugging detail message.
219: *
220: * @param message The message to be logged
221: */
222: private static void log(String message) {
223:
224: System.out.print("Bootstrap: ");
225: System.out.println(message);
226:
227: }
228:
229: /**
230: * Log a debugging detail message with an exception.
231: *
232: * @param message The message to be logged
233: * @param exception The exception to be logged
234: */
235: private static void log(String message, Throwable exception) {
236:
237: log(message);
238: exception.printStackTrace(System.out);
239:
240: }
241:
242: }
|