这个是在加载器之前初始化的负责加载catalina.properties,并将它们写进系统变量中
static {
loadProperties();
}
类初始化快只负责调用loadProperties()方法
private static void loadProperties() {
InputStream is = null;
try {
String configUrl = System.getProperty("catalina.config");
if (configUrl != null) {
is = (new URL(configUrl)).openStream();
}
} catch (Throwable t) {
handleThrowable(t);
}
if (is == null) {
try {
File home = new File(Bootstrap.getCatalinaBase());
File conf = new File(home, "conf");
File propsFile = new File(conf, "catalina.properties");
is = new FileInputStream(propsFile);
} catch (Throwable t) {
handleThrowable(t);
}
}
if (is == null) {
try {
is = CatalinaProperties.class.getResourceAsStream
("/org/apache/catalina/startup/catalina.properties");
} catch (Throwable t) {
handleThrowable(t);
}
}
if (is != null) {
try {
properties = new Properties();
properties.load(is);
} catch (Throwable t) {
handleThrowable(t);
log.warn(t);
} finally {
try {
is.close();
} catch (IOException ioe) {
log.warn("Could not close catalina.properties", ioe);
}
}
}
if ((is == null)) {
// Do something
log.warn("Failed to load catalina.properties");
// That's fine - we have reasonable defaults.
properties = new Properties();
}
// Register the properties as system properties
Enumeration<?> enumeration = properties.propertyNames();
while (enumeration.hasMoreElements()) {
String name = (String) enumeration.nextElement();
String value = properties.getProperty(name);
if (value != null) {
System.setProperty(name, value);
}
}
}
前面一段是负责找到catalina.properties文件,最后使用遍历将这个写进System中
public static String getProperty(String name) {
return properties.getProperty(name);
}
System.getProperties和CatalinaProperties.getProperty(name + “.loader”)一样的结果