[英]Java class can be run by double click but not task scheduler
Java class in *.bat can be run by double click but not task scheduler. * .bat中的Java类可以通过双击运行,但不能通过任务计划程序运行。
What's the problem? 有什么问题? Classpath or something else?
类路径还是其他?
What should I do? 我该怎么办?
Java .class files normally cannot be run via a double click; Java .class文件通常无法通过双击运行。 JAR archives can, but only through the association of the file type with a JVM executable.
JAR归档可以,但只能通过文件类型与JVM可执行文件的关联来实现。 They're like Word documents - if you "execute" those with a double click, what actually happens is that Word is started and given the document as input.
它们就像Word文档一样-如果您通过双击“执行”这些文档,则实际发生的是启动Word并将文档作为输入。
If you want to run a JAR archive in the task scheduler, you'll have to do call the JVM executable like this: 如果要在任务计划程序中运行JAR存档,则必须像这样调用JVM可执行文件:
C:\Program Files\jre6\bin\javaw.exe -jar C:\wherever\program.jar
Running Java .class files can be done like this as well, but you'll have to drop the -jar
switch, use -cp
to specify the classpath and in the end put the class name, not the file name, ie something like "com.initech.app.MainClass" 运行Java .class文件也可以这样做,但是您必须删除
-jar
开关,使用-cp
指定类路径,最后放置类名,而不是文件名,即“ com.initech.app.MainClass”
The .bat file probably sets the environment. .bat文件可能设置了环境。 Just run the .bat from the task scheduler.
只需从任务计划程序运行.bat。
编写执行您的jar的Shell或bat脚本,并将其放入任务计划程序中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.