How do I get java to output to a log when run from

2019-05-14 23:48发布

问题:

I have a java file called "Ares.jar" that runs every 5 minutes via windows scheduled tasks, the batch calls:

java -jar Ares.jar >> Ares.log  

I'm not seeing any error output, is there some way to make the errors (system.err.println / exception.printStackTrace(); )go to a file?

Thanks.

回答1:

java -jar Ares.jar > Ares.log 2>&1 

The second part of this command will redirect stderr to stdout, ensuring that both appear in the same file.

If you want regular logs and error logs in separate files, just use:

java -jar Ares.jar > Ares.log 2>Ares.error.log

You can get the full details of everything that is possible in the documentation, available from Microsoft: http://technet.microsoft.com/en-us/library/bb490982.aspx