Schedule to run a executable jar file on windows 7

5.5k Views Asked by At

I created a task in task scheduler on Windows 7 system and made it repeatable every 10 minutes.

In program, i selected the executable java jar file. But it does not run the jar file at the scheduled time.

When i double click and run the jar file, it runs as desired. The Jar just pops up a dialog box.

Any inputs as to where i am going wrong is appreciated.

1

There are 1 best solutions below

1
On BEST ANSWER

Firstly make sure Java is set in the enviroment PATH by opening cmd.exe and typing java -version. If you get back the java version, then you are fine. (If not see Update the PATH Environment Variable (Microsoft Windows))

Then create a text file, save it as run.bat and type inside:

java -jar <insertjavajarnamehere>.jar

Make sure the bat is in the same directory as your jar file.

Now go in Windows Task Scheduler > Create Basic Task > ... >Start a program > and browse for your .bat file.

Also, set Start in to the path where your .bat and .jar are located. Create your task and it should run fine afterwards.

Edit: To avoid the shell being visible a simple trick is to create a VBS file

Create a run-invisible.vbs, and type:

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("C:\Users\pathtobat\run.bat"), 0, True

And schedule that instead of the bat (make sure you update the path to your bat in the vbs file)