How can I use Task Scheduler to schedule a .jar file?

2

1

I have an executable jar file and I am trying to create a scheduled task for every day using windows Task Scheduler I go through the following steps:

open Task Scheduler -> Create Basic Task -> name task -> set trigger to daily -> set the time for run -> select start a program for Action -> browse and select my .jar file -> finish

However it does not run, I saw on the internet that the start a program action only works with .exe files, is there a way to get this to run my .jar file? By the way I am using windows 7 and have the latest jdk/sdk for java.

Beef

Posted 2011-12-01T17:18:55.523

Reputation: 123

Answers

4

Schedule java.exe or javaw.exe instead, with the following command-line arguments:

javaw -jar myfile.jar

(On Windows, java is for console-based programs while javaw is for graphical ones.)

user1686

Posted 2011-12-01T17:18:55.523

Reputation: 283 655

1I cant seem to get this to work, I am using javaw, because the program will execute some code on start up but eventually it will require user response through the GUI. – Beef – 2011-12-01T17:57:23.710

1@Beef: Try specifying the full paths to javaw.exe and your .jar file. – user1686 – 2011-12-01T21:38:45.767

4

You might be able to create a batch file to run the java program.

@echo off
java filepathto.jar

However if the java program can not be run without any user input it would be useless.

anzenketh

Posted 2011-12-01T17:18:55.523

Reputation: 161

1this works but it leaving a hanging command prompt window open, is there anyways to get it to close the command prompt window once my program has actually opened? – Beef – 2011-12-01T17:54:25.510

1@Beef: Use javaw instead of java. (That's the only difference between them — java is marked as "console" program, so Windows opens the console window (not command prompt) automatically. Both java and javaw) can display graphical windows.) – user1686 – 2011-12-01T18:06:48.913

1@grawity I have added those changes since reading your answer above, still leaves the cmd window hanging till I close my GUI – Beef – 2011-12-01T18:26:40.377

2@Beef: Prefix the java(w) command with start "", it should allow the console to close. – user1686 – 2011-12-01T21:39:13.207

3

A slightly roundabout way would be to download this Batch to EXE converter, use it to convert anzenketh's batch file to an exe with the setting Invisible Application, and including the jar file. This way you could directly tell task scheduler to run the resulting exe, and you would only have one exe to keep track of instead of the jar and the bat.

SaintWacko

Posted 2011-12-01T17:18:55.523

Reputation: 1 482