How to create Windows Task Scheduler and run a Java application?

Overview

In this post, we will learn to create Windows Task Scheduler to run/start our application.

Here, I will explain how we can schedule to start our Java application with windows task scheduler.

Prerequisite

  • A jar file that contains our java application

Solution

We need to create a bat file so that the windows task scheduler will start our java application. If you don’t know how to create a bat file then please check out the article how to run a jar file from batch file. Where I have explained about it.

I am assuming that you have created a bat file that executes the jar file.

Let’s assume the following use case.

Use case

We have a jar file and want to start/run it by windows task scheduler everyday in every 1 hour.

We will be following the above use case to create a windows task scheduler.

Steps to create a Windows Task Scheduler

  1. Search Task Scheduler. You can do this after clicking icon. You may see the following:
Windows task scheduler
How to create Windows Task Scheduler and run a Java application? 3
  1. Open it and the following window will be displayed
windows task scheduler window
How to create Windows Task Scheduler and run a Java application? 4
  1. Under Task Scheduler (Local), select Task Scheduler Library and click New Folder from the Actions panel and give a folder name, and click ok. (I would recommend you to create a folder and keep all the tasks under it. Otherwise, you may find difficulties in locating the newly created task.)
  2. Select the folder you’ve created earlier.
  3. Now you can click on the Create task… which is under the Actions panel on the right side.
  4. In the general tab:
    • Name: MyTask
    • Description: Demo Task
  5. On the Triggers tab:
    • Click on the New… button.
    • Select Daily
    • On the Advanced Setting, check Repeat task every. The default value is 1 Hour.
  6. On the Actions tab:
    • Click on the New.. button.
    • Things to remember:
      • If your batch file location is: C:\my-folder\HelloWorld.bat then should set the value,
      • Program/Script: HelloWorld.bat
      • Start in (Optional): C:\my-folder
  7. If you want to change the configuration based on your requirement you can modify the Conditions and Settings tab accordingly.

Optional but important

If your task is not stopping properly and causing problem while starting next time then, open your task from Task Scheduler list, got to Setting tab select Stop the existing instance option which can be found under the If the task is already running, then the following rule applies: section.
  1. Click Ok to all popup one by one.
  2. The task should be created successfully.

Now, you can test the task.

Select the folder you have created.

Select the Task you’ve created.

Right click on it and click Run. You can also run the task rom Actions panel in the right side.

Conclusion

In the post, we’ve successfully created a task in Windows Task Scheduler to run our Java application.


Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments