Java批处理调度,使用任务调度程序运行java jar(来自批处理文件)

作者遇到在Windows任务调度器中运行批处理文件,调用Java jar时出现ClassNotFoundException的问题。推测可能的原因是当前目录不同导致jar文件找不到。解决办法建议在bat脚本开头设置正确的路径。讨论了从命令行与任务调度器执行差异,以及如何调整环境变量以确保正确加载jar文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am scheduling a task (with windows task scheduler) which simply run a batch file.

this batch is running a jar file (Java program) with a simple "Java -jar test.jar".

When i run the script from the command line manually, the java program runs well and no exception is shown.

but when the task schedular does the same (calling the command), the java program ends with an exception: "ClassNotFoundException" for one of the classes which is in my jar.

What way be the cause of this? what is the diffrence when calling the jar from the command line and from the task scheduler?

Thanks.

解决方案

I reckon that probably the "current directory" is different, and as a consequence java doesn't find the jar at all. In the first line of your .bat, can you do a cd \path\that\you\expect before you execute java?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值