/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.startup; import java.io.File; import java.lang.reflect.Method; import java.util.ArrayList; import org.apache.catalina.Globals; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; import org.apache.tomcat.util.ExceptionUtils; /** *
General purpose wrapper for command line tools that should execute in an * environment with the common class loader environment set up by Catalina. * This should be executed from a command line script that conforms to * the following requirements:
*catalina.home system property configured with
* the pathname of the Tomcat installation directory.bootstrap.jar and
* $JAVA_HOME/lib/tools.jar.The command line to execute the tool looks like:
*
* java -classpath $CLASSPATH org.apache.catalina.startup.Tool \
* ${options} ${classname} ${arguments}
*
*
* with the following replacement contents: *
ant.home system property
* to corresponding to the value of catalina.home
* (useful when your command line tool runs Ant).common/classes and
* common/lib to the class loader repositories.server/classes and
* server/lib to the class loader repositories.shared/classes and
* shared/lib to the class loader repositories.main() method.ant.home system property?
*/
private static boolean ant = false;
/**
* The pathname of our installation base directory.
*/
private static final String catalinaHome =
System.getProperty(Globals.CATALINA_HOME_PROP);
/**
* Include common classes in the repositories?
*/
private static boolean common = false;
/**
* Include server classes in the repositories?
*/
private static boolean server = false;
/**
* Include shared classes in the repositories?
*/
private static boolean shared = false;
// ----------------------------------------------------------- Main Program
/**
* The main program for the bootstrap.
*
* @param args Command line arguments to be processed
*/
@SuppressWarnings("null")
public static void main(String args[]) {
// Verify that "catalina.home" was passed.
if (catalinaHome == null) {
log.error("Must set '" + Globals.CATALINA_HOME_PROP + "' system property");
System.exit(1);
}
// Process command line options
int index = 0;
while (true) {
if (index == args.length) {
usage();
System.exit(1);
}
if ("-ant".equals(args[index]))
ant = true;
else if ("-common".equals(args[index]))
common = true;
else if ("-server".equals(args[index]))
server = true;
else if ("-shared".equals(args[index]))
shared = true;
else
break;
index++;
}
if (index > args.length) {
usage();
System.exit(1);
}
// Set "ant.home" if requested
if (ant)
System.setProperty("ant.home", catalinaHome);
// Construct the class loader we will be using
ClassLoader classLoader = null;
try {
ArrayList