/* * 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;
/** * Bootstrap loader for Catalina. This application constructs a class loader * for use in loading the Catalina internal classes (by accumulating all of the * JAR files found in the "server" directory under "catalina.home"), and * starts the regular execution of the container. The purpose of this * roundabout approach is to keep the Catalina internal classes (and any * other classes they depend on, such as an XML parser) out of the system * class path and therefore not visible to application level classes. * * @author Craig R. McClanahan * @author Remy Maucherat
*/ publicfinalclass Bootstrap {
static { // Will always be non-null
String userDir = System.getProperty("user.dir");
// Home first
String home = System.getProperty(Constants.CATALINA_HOME_PROP);
File homeFile = null;
if (home != null) {
File f = new File(home); try {
homeFile = f.getCanonicalFile();
} catch (IOException ioe) {
homeFile = f.getAbsoluteFile();
}
}
if (homeFile == null) { // First fall-back. See if current directory is a bin directory // in a normal Tomcat install
File bootstrapJar = new File(userDir, "bootstrap.jar");
if (bootstrapJar.exists()) {
File f = new File(userDir, ".."); try {
homeFile = f.getCanonicalFile();
} catch (IOException ioe) {
homeFile = f.getAbsoluteFile();
}
}
}
if (homeFile == null) { // Second fall-back. Use current directory
File f = new File(userDir); try {
homeFile = f.getCanonicalFile();
} catch (IOException ioe) {
homeFile = f.getAbsoluteFile();
}
}
/** * Destroy the Catalina Daemon.
*/ publicvoid destroy() {
// FIXME
}
/** * Main method and entry point when starting Tomcat via the provided * scripts. * * @param args Command line arguments to be processed
*/ publicstaticvoid main(String args[]) {
synchronized (daemonLock) { if (daemon == null) { // Don't set daemon until init() has completed
Bootstrap bootstrap = new Bootstrap(); try {
bootstrap.init();
} catch (Throwable t) {
handleThrowable(t);
log.error("Init exception", t); return;
}
daemon = bootstrap;
} else { // When running as a service the call to stop will be on a new // thread so make sure the correct class loader is used to // prevent a range of class not found exceptions. Thread.currentThread().setContextClassLoader(daemon.catalinaLoader);
}
}
/** * Obtain the name of configured home (binary) directory. Note that home and * base may be the same (and are by default). * @return the catalina home
*/ publicstatic String getCatalinaHome() { return catalinaHomeFile.getPath();
}
/** * Obtain the name of the configured base (instance) directory. Note that * home and base may be the same (and are by default). If this is not set * the value returned by {@link #getCatalinaHome()} will be used. * @return the catalina base
*/ publicstatic String getCatalinaBase() { return catalinaBaseFile.getPath();
}
/** * Obtain the configured home (binary) directory. Note that home and * base may be the same (and are by default). * @return the catalina home as a file
*/ publicstatic File getCatalinaHomeFile() { return catalinaHomeFile;
}
/** * Obtain the configured base (instance) directory. Note that * home and base may be the same (and are by default). If this is not set * the value returned by {@link #getCatalinaHomeFile()} will be used. * @return the catalina base as a file
*/ publicstatic File getCatalinaBaseFile() { return catalinaBaseFile;
}
// Copied from ExceptionUtils since that class is not visible during start staticvoid handleThrowable(Throwable t) { if (t instanceof ThreadDeath) { throw (ThreadDeath) t;
} if (t instanceof StackOverflowError) { // Swallow silently - it should be recoverable return;
} if (t instanceof VirtualMachineError) { throw (VirtualMachineError) t;
} // All other instances of Throwable will be silently swallowed
}
// Copied from ExceptionUtils so that there is no dependency on utils static Throwable unwrapInvocationTargetException(Throwable t) { if (t instanceof InvocationTargetException && t.getCause() != null) { return t.getCause();
} return t;
}
// Protected for unit testing protectedstatic String[] getPaths(String value) {
List<String> result = new ArrayList<>();
Matcher matcher = PATH_PATTERN.matcher(value);
while (matcher.find()) {
String path = value.substring(matcher.start(), matcher.end());
path = path.trim(); if (path.length() == 0) { continue;
}
char first = path.charAt(0); char last = path.charAt(path.length() - 1);
if (first == '"' && last == '"' && path.length() > 1) {
path = path.substring(1, path.length() - 1);
path = path.trim(); if (path.length() == 0) { continue;
}
} elseif (path.contains("\"")) { // Unbalanced quotes // Too early to use standard i18n support. The class path hasn't // been configured. thrownew IllegalArgumentException( "The double quote [\"] character can only be used to quote paths. It must " + "not appear in a path. This loader path is not valid: [" + value + "]");
} else { // Not quoted - NO-OP
}
result.add(path);
}
return result.toArray(new String[0]);
}
}
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.