Schedule A Java Program Windows 7 – Windows 7 Cron Job

Recently I wrote a Java program to clean up a directory on my Windows 7 machine. I wanted this java program to run each day at 5pm. Here is how I scheduled it to do so.

1 – Compiled my java program into a jar file named “FileArchiver.jar”

2 – Created a batch file with the command which runs my program. Creating a batch file is as simple as opening notepad and saving the file with a “.bat” extension. The contents of my batch file, which is named “archive.bat”, consisted entirely of the following line:

java -jar “C:\GlenIris\NetBeansProjects\FileArchiver\dist\FileArchiver.jar” C:\\GlenIris\\NetBeansProjects\\FileArchiver\\properties\\securecam.properties

I then tested that the batch file ran my program by double clicking on it. It did.

3 – Schedule the task to run every day at 5. I did this by opening Windows Task Scheduler like so:

Start>>All Programs>>Accessories>>System Tools>>Task Scheduler

On the right hand side, click ‘create task’.

Select ‘Start a program’ from the action dropdown. In the text field, type the path to the bat file. eg:

C:\GlenIris\archive.bat

Each option in each of the other tabs is now self explanatory.

A divil for scheduling tasks on Windows Machines was Stefan Schwarz

A divil for scheduling tasks on Windows Machines was Stefan Schwarz

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: