If you want a Java application to run daily, hourly or on some other frequency and the server is Windows, this entry provides a step-by-step method for configuring such a system.  Below are the basic steps in brief:

1. write java class or obtain classes to use
2. move class or classes to root location:  java_home\bin (where java.exe is found)
3. put your classes in the file path descending from bin, as usual (i.e. com.utilities.mycompany)
4. put .properties file (if any) in bin directory (java_home\bin )

5. create a batch file on desktop or anywhere.  Inside batch file place your java class invocation
6. point to batch file in Windows Scheduler.

7. Configure Windows Scheduler to run on some schedule.
 
Details of Process (uses same sequence as above):

1. write java class or obtain classes to use. Can also use jar files, of course.

2. move class or classes to root location:  java_home\bin (where java.exe is found). If you don't have java_home environment variable set search for java.exe and use the JRE/JDK folder that matches the version of Java JVM you're using. It's often found in c:\program files\java...

3. put your classes in the file path descending from bin, as usual (i.e. com.utilities.mycompany).  See image below: 

 



4. put .properties file (if any) in bin directory (java_home\bin ). In this example: C:\Program Files\Java\jdk1.5.0_09\bin

5. create a batch file on desktop or anywhere.  Inside batch file place your java class invocation.  Here is a sample batch file. Of course, you can get as fancy and include as many features as you want. Check the Internet for details about how to write batch (.bat) files...this is an entire subject in itself:

echo Running Java Move File utility
echo %date% %time% Start of Running Java Move File utility> c:\test.log
cd C:\Program Files\Java\jdk1.5.0_09\bin
java -cp ".;" com.util.cmmc.CopyAndDelete 1>>c:\test.log 2>>&1
echo Batch file completed

Intrepretation of bat file (in parentheses)

echo Running Java Move File utility (just a comment)

echo %date% %time% Start of Running Java Move File utility> c:\test.log  (this line puts a timestamp and title into a file called test.log)

cd C:\Program Files\Java\jdk1.5.0_09\bin (this ensures you are in correct directory to launch java JVM)

java -cp ".;" com.util.cmmc.CopyAndDelete 1>>c:\test.log 2>>&1 (this is the key line that launches your app. In this case it's called CopyAndDelete. Classpath has no supporting classes besides default classes. Note that standard output statements are written to the same log file)
echo Batch file completed (just a comment)

6. point to batch file in Windows Scheduler. Open Windows Scheduler by Contol Panel | Scheduled Tasks (Windows 2003 Server Enterprise Ed.). Create a new task. Point to the .bat file you just created:

  

 



7. Configure Windows Scheduler to run on a schedule. Use Advanced settings if you need to further define scheduled run time.







Advanced settings allow repeating schedule and frequency not found in the basic settings:

 




Setup is now complete. You can do a sample run (independent of schedule) by right clicking on the Scheduled Task (at Explorer level - folder level) and clicking Run.

 

Note that there are many options for creating a .bat file, setting up scheduler, logging, etc. This blog entry shows how to do a basic, workable system from start-to-finish.  You can use this as a starting point and construct what you need from this example working system.