如何避免打印文件未找到异常(..\conf\log4j.xml) 在运行以下命令时具有完整的堆栈跟踪。我需要处理此异常并打印消息,而不是完整的堆栈跟踪。
"java -jar -Dlog4j.configuration="file:..conflog4j.xml" ..simulationengine.jar"
Error: log4j:ERROR Could not parse url [file:..//conf//log4j.xml].
java.io.FileNotFoundException: ..conflog4j.xml (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
java -jar ..simulationengine.jar
,将 log4j.xml 文件放在类路径的根目录中,例如在 ..\模拟引擎.jar它将正常工作。
- 网址不能包含反斜杠。尝试使用正斜杠。
-
-jar 的 JAR 文件参数必须跟在 -jar 选项后面。您的命令行全部混淆了。
java -Dlog4j.comfiguration=... -jar xxx.jar