简体   繁体   English

Java程序使用Windows Task Scheduler启动,但未在批处理文件夹中创建日志文件

[英]Java program started using windows task scheduler but not creating log files in batch file folder

I have started java program (with batch file script) using Windows task scheduler. 我已经使用Windows任务计划程序启动了Java程序(带有批处理文件脚本)。 and in my log4.properties 并在我的log4.properties中

log4j.rootLogger=ALL, file1
log4j.appender.file1=org.apache.log4j.RollingFileAppender
log4j.appender.file1.Threshold=INFO
log4j.appender.file1.File=personal-info.log 
log4j.appender.file1.MaxFileSize=10240KB
log4j.appender.file1.MaxBackupIndex=10
log4j.appender.file1.layout=org.apache.log4j.PatternLayout
log4j.appender.file1.layout.ConversionPattern = %d{ISO8601} %-5p [%t] [%F:%L] : %m%n
log4j.logger.com.personal=INFO,  file1
log4j.additivity.com.personal=false
log4j.additivity.org.springframework=false
log4j.additivity.org.jboss=false
log4j.additivity.org.hibernate=false
log4j.additivity.org.dozer=false

When I start my batch file from command line, this file gets created in same folder of batch file, but when I start it from windows task scheduler, it doesn't create log files either in batch file folder or anywhere else in machine. 当我从命令行启动批处理文件时,该文件将在批处理文件的同一文件夹中创建,但是当我从Windows Task Scheduler启动该文件时,它既不在批处理文件文件夹中也不在计算机的任何其他位置中创建日志文件。

One more thing, this task was started by other user, has anyone else has this issue before and solution is to provide physical path of folder in log4.properties? 还有一件事,该任务由其他用户启动,其他任何人之前都遇到过此问题,解决方案是在log4.properties中提供文件夹的物理路径?

You will encounter path and classpath issue with Task Scheduler. 您将在Task Scheduler中遇到路径和类路径问题。 The user set to execute the scheduled task probably has a different PATH and classpath definition. 设置为执行计划任务的用户可能具有不同的PATH和类路径定义。 The user set to execute the scheduled task has user privilege that could impact your batch execution. 设置为执行计划任务的用户具有用户权限,这可能会影响您的批处理执行。 Your batch file has to set everything in order to run as you expect. 您的批处理文件必须设置所有内容才能按预期运行。

Hope this could help. 希望这会有所帮助。

regards, Yann 问候,扬

I have the same problem when the .bat file is executed by the Task Scheduler to start my small Java application. 当任务计划程序执行.bat文件以启动我的小型Java应用程序时,我遇到了同样的问题。 The log4j logfiles are simply not being created. 根本不会创建log4j日志文件。 But when I run the batch file from the command line everything works fine. 但是,当我从命令行运行批处理文件时,一切正常。 As rishman suggested, there has to be something with PATH/classpath. 正如Rishman所建议的那样,PATH / classpath必须具有某些内容。

However you can save to file the logs generated by your batch file: 但是,您可以将由批处理文件生成的日志保存到文件中:

在此处输入图片说明

This will create a .log file in the location where the batch file is. 这将在批处理文件所在的位置创建一个.log文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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