Run a jar file using windows scheduler

烂漫一生 提交于 2019-11-26 17:36:16

问题


I have jar file which I want to run from windows scheduler in windows 7

I have Given the path of java.exe in path/script and -jar c:\abc\ab.jar in the arguments field.

But it does not run. I have also tried it with help of a bat file, but it does not run. What is needed to be done to run the jar file?

My jar file creates files and updates a database.


回答1:


Run a java jar from Task Scheduler (Windows 7 Professional 64 bit)

I'll be configuring it to run every 5 minutes.

Step 1, install java, make sure it is available from commandline

You should be able to run your java jar from the bare cmd commandline. Specify the full java directory like this: (This is the command I used)

C:\ProgramData\Oracle\Java\javapath\java.exe -jar C:\repo\curium.jar

Step 2, Open task scheduler:

In the Start menu search bar, search for "scheduler" and "Task Scheduler" should pop up. It is buried in the control panel: Control Panel -> System And Security -> Administrative tools -> Task Scheduler.

Step 3, make a new scheduled task:

In the left pane, right click "Task Scheduler Library". Choose: "New Basic Task". Give it any name.

Choose next. Click "Daily", (the configuration for re-runs every minute will be done later).

Choose next. Recur every 1 day. Have it start a 5 minutes from now. choose next. Click "Start a program".

Step 4, configure your java to run:

In the "Program/script" box put the full path to your java, your path may be different. Double check with cmd command where java

C:\ProgramData\Oracle\Java\javapath\java.exe

In the "Add arguments" box put this:

-jar C:\repo\curium.jar

Click next, click finish.

Step 5, Right click your new task for further configuration:

Right click your item -> Properties.

Choose the bubble: "Run whether user is logged in or not"

Under the "triggers" tab. Select your Daily task and choose Edit.

Step 6, configure the repeat-task triggers

Begin the task: "On a schedule".

Choose Repeat task every: "5 minutes". Choose the enabled checkbox. Click ok. Save.

You will be prompted for your windows username and password. Add and press OK.

Step 7, ensure it is working

Wait 5 minutes for it to run. Or force run it by right clicking -> Run.

Right click your task, choose properties. Choose "History" tab.

There should be a row there revealing when it ran. If you want to know if it completed successfully, you'll have to pipe your output to a log file.

Step 8, see if it survives a reboot

Reboot the computer, and see if it stays on. If it does you are done.




回答2:


If your JAR creates files, I think you just to specify a working directory in the Start in field when you create your task. For example:

  • Program script: C:\Program Files\Java\jre7\bin\java.exe
  • Add arguments: -jar c:\abc\ab.jar
  • Start in: c:\abc


来源:https://stackoverflow.com/questions/15783553/run-a-jar-file-using-windows-scheduler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!