Reference :
http://stackoverflow.com/questions/12034177/running-a-java-program-as-a-scheduled-task
http://bbs.csdn.net/topics/300191012
http://devinsun.iteye.com/blog/454350
Requirement:
For testing, need to send some transactions during midnight.
Testing program(java) is ready, the thing is how to schedule it to run at midnight.
Tools to use :
1) Windows Scheduler
2)Eclipse and Jar file exportation
Steps:
1.In Eclipse, Export java project (having main class with main method) to a jar
1) following the pic as below , same steps as mentioned in :http://devinsun.iteye.com/blog/454350
2) things to note is the MANIFEST.MF , mine is like below (there is 2 blank lines in the end of the file, no verifying ...:))
Manifest-Version: 1.0
Main-Class: com.gb.term.simulator.main.TxRateRequestSimulatorTest
Class-Path: lib/log4j-1.2.16.jar lib/commons-codec-1.4.jar lib/commons-lang3-3.1.jar lib/contiperf-2.3.0.jar lib/jpos.jar lib/slf4j-api-1.6.1.jar lib/slf4j-log4j12-1.6.1.jar
3)after generate the jar , structure like this :
3. firstly, try to create a cmd file to call jar file : runScript.cmd, this can run independently. But when setup in Windows scheduler and the scheduled time is due, the cmd prompt window just flashed without running the logic inside. No time to investigate ,just give up
@echo off
REM Eventually change directory to the program directory
cd D:\Working\JarWork\
REM run the program
"C:\Program Files\Java\jdk1.7.0_21\bin\java.exe" -jar "TXRateRequestSimulatorTest.jar"
4.Second try by following : http://www.coderanch.com/t/570071/gc/schedule-jar-file-windows-task
Program/script: "C:\Program Files\Java\jdk1.7.0_21\bin\java.exe"
Arguments: -jar D:\Working\JarWork\TXRateRequestSimulatorTest.jar
Start in (optional):C:\Users\xding\Desktop (note: this is optional, if there is log, maybe log will be show in this path if no special config)
DONE!! ^_^