Run a jar file using windows scheduler

Solution 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.

Solution 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