1 17 18 19 package org.apache.catalina.startup; 20 21 22 import java.io.File ; 23 import java.lang.reflect.Method ; 24 import java.util.ArrayList ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 30 72 73 public final class Tool { 74 75 76 private static Log log = LogFactory.getLog(Tool.class); 77 78 80 81 84 private static boolean ant = false; 85 86 87 90 private static String catalinaHome = System.getProperty("catalina.home"); 91 92 93 96 private static boolean common = false; 97 98 99 102 private static boolean server = false; 103 104 105 108 private static boolean shared = false; 109 110 111 113 114 119 public static void main(String args[]) { 120 121 if (catalinaHome == null) { 123 log.error("Must set 'catalina.home' system property"); 124 System.exit(1); 125 } 126 127 int index = 0; 129 while (true) { 130 if (index == args.length) { 131 usage(); 132 System.exit(1); 133 } 134 if ("-ant".equals(args[index])) 135 ant = true; 136 else if ("-common".equals(args[index])) 137 common = true; 138 else if ("-server".equals(args[index])) 139 server = true; 140 else if ("-shared".equals(args[index])) 141 shared = true; 142 else 143 break; 144 index++; 145 } 146 if (index > args.length) { 147 usage(); 148 System.exit(1); 149 } 150 151 if (ant) 153 System.setProperty("ant.home", catalinaHome); 154 155 ClassLoader classLoader = null; 157 try { 158 ArrayList packed = new ArrayList (); 159 ArrayList unpacked = new ArrayList (); 160 unpacked.add(new File (catalinaHome, "classes")); 161 packed.add(new File (catalinaHome, "lib")); 162 if (common) { 163 unpacked.add(new File (catalinaHome, 164 "common" + File.separator + "classes")); 165 packed.add(new File (catalinaHome, 166 "common" + File.separator + "lib")); 167 } 168 if (server) { 169 unpacked.add(new File (catalinaHome, 170 "server" + File.separator + "classes")); 171 packed.add(new File (catalinaHome, 172 "server" + File.separator + "lib")); 173 } 174 if (shared) { 175 unpacked.add(new File (catalinaHome, 176 "shared" + File.separator + "classes")); 177 packed.add(new File (catalinaHome, 178 "shared" + File.separator + "lib")); 179 } 180 classLoader = 181 ClassLoaderFactory.createClassLoader 182 ((File []) unpacked.toArray(new File [0]), 183 (File []) packed.toArray(new File [0]), 184 null); 185 } catch (Throwable t) { 186 log.error("Class loader creation threw exception", t); 187 System.exit(1); 188 } 189 Thread.currentThread().setContextClassLoader(classLoader); 190 191 Class clazz = null; 193 String className = args[index++]; 194 try { 195 if (log.isDebugEnabled()) 196 log.debug("Loading application class " + className); 197 clazz = classLoader.loadClass(className); 198 } catch (Throwable t) { 199 log.error("Exception creating instance of " + className, t); 200 System.exit(1); 201 } 202 203 Method method = null; 205 String params[] = new String [args.length - index]; 206 System.arraycopy(args, index, params, 0, params.length); 207 try { 208 if (log.isDebugEnabled()) 209 log.debug("Identifying main() method"); 210 String methodName = "main"; 211 Class paramTypes[] = new Class [1]; 212 paramTypes[0] = params.getClass(); 213 method = clazz.getMethod(methodName, paramTypes); 214 } catch (Throwable t) { 215 log.error("Exception locating main() method", t); 216 System.exit(1); 217 } 218 219 try { 221 if (log.isDebugEnabled()) 222 log.debug("Calling main() method"); 223 Object paramValues[] = new Object [1]; 224 paramValues[0] = params; 225 method.invoke(null, paramValues); 226 } catch (Throwable t) { 227 log.error("Exception calling main() method", t); 228 System.exit(1); 229 } 230 231 } 232 233 234 237 private static void usage() { 238 239 log.info("Usage: java org.apache.catalina.startup.Tool [<options>] <class> [<arguments>]"); 240 241 } 242 243 244 } 245 | Popular Tags |