使用任务调度程序运行java jar(来自批处理文件) [英] Using task scheduler for running java jar (from batch file)

查看:182
本文介绍了使用任务调度程序运行java jar(来自批处理文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在安排一个任务(使用Windows任务调度程序),只需运行一个批处理文件。

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

这个批处理正在运行一个简单的jar文件(Java程序) Java -jar test.jar。

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

当我手动从命令行运行脚本时,java程序运行良好,不会显示异常。

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

但是当任务调度程序执行相同操作(调用命令)时,java程序以异常结束:ClassNotFoundException,用于我的jar中的一个类。

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.

这是什么原因?从命令行和任务调度程序调用jar时的差异是什么?

谢谢。

推荐答案

我认为可能当前目录不同,因此java根本找不到jar。在你的.bat的第一行,你可以在执行java之前做一个 cd \ path \that \you\expect 吗?

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?

这篇关于使用任务调度程序运行java jar(来自批处理文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆