简体   繁体   中英

Start java jar with log4j on Windows 2012 R2

I need to start java jar with log4j config in specific location in Windows 2012 R2 Powershell (or command line).

I tried the following command :

java -jar C:\myApp\myApp.jar -Duser.dir=C:\myApp -Dlog4j.configuration=file:C:\myApp\resources\log4j.xml

But the app fails to start with log4j error(after the WARN) :

log4j:WARN No appenders could be found for logger (cz.mypackage.Myclass).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

The same jar file with same log4j.xml, runned by same command on Windows 2003 (with same version of Java) starts correctly.

I also tried several modifications of log4j file URI ("file://C:\\myApp\\resources\\log4j.xml","file://C:/myApp/resources/log4j.xml", "file://C:\\\\myApp\\\\resources\\\\log4j.xml" or "file:C:\\\\myApp\\\\resources\\\\log4j.xml") as I found all over Internet.

Does anyone has any suggestions, how to start the jar?

SOLUTION : The magic is in using quotes and running from administrator powershel (I don't know why, but it works):

java -jar "C:\myApp\myApp.jar" -Duser.dir=C:\myApp -Dlog4j.configuration=file:C:\myApp\resources\log4j.xml

神奇之处在于使用引号并从管理员powershel运行(我不知道为什么,但是它可以工作):

java -jar "C:\myApp\myApp.jar" -Duser.dir=C:\myApp -Dlog4j.configuration=file:C:\myApp\resources\log4j.xml

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM