Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
529 views
in Technique[技术] by (71.8m points)

scheduled tasks - Run a jar file using windows scheduler

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:abcab.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:ProgramDataOracleJavajavapathjava.exe -jar C:
epocurium.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:ProgramDataOracleJavajavapathjava.exe

In the "Add arguments" box put this:

-jar C:
epocurium.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...