- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我需要获取在 logging.properties 中配置的 catalina.out 文件的路径。
有没有办法在不知道属性文件路径的情况下通过 java 检索属性“1catalina.org.apache.juli.FileHandler.directory”?
最佳答案
如果我没理解错的话,您想要读取 Tomcat logging.properties
文件的一个属性。正如您在 Tomcat FAQ for Logging 中看到的那样, java.util.logging.config.file
用于定义属性文件的路径。
然后您可以通过 Java System Properties 检索此路径:
String pathLogProps = System.getProperty("java.util.logging.config.file");
Properties properties = new Properties();
try {
properties.load(new FileInputStream(pathLogProps));
System.out.println(prop.getProperty("database"));
} catch (IOException ex) {
ex.printStackTrace();
}
如果未设置,我将遵循 Apache Tomcat 7 Logging Documentation 中的提示:
JULI is enabled by default, and supports per classloader configuration, in addition to the regular global java.util.logging configuration. This means that logging can be configured at the following layers:
- Globally. That is usually done in the
${catalina.base}/conf/logging.properties
file. The file is specified by the java.util.logging.config.file System property which is set by the startup scripts.- If it is not readable or is not configured, the default is to use the
${java.home}/lib/logging.properties
file in the JRE. In the web application. The file will beWEB-INF/classes/logging.properties
默认情况下,logging.properties
文件的路径应该在环境变量 catalina.base
上可用,分别为 CATALINA_BASE
。
关于java - 如何在 java 程序中检索 catalina.out 的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11773919/
我是一名优秀的程序员,十分优秀!