Sunday 19 July 2015

Run a Jar File Using Windows Task Scheduler

Importance:

In Automation Testing, we have to schedule an execution of our Test Script in midnight then such thing is very much important.

The Automation tester schedule an execution of test script in windows task scheduler in night, when the the time is trigger the execution of script is going to run automatically and store the result in the form of report. so in the next day the automation tester will look up into the report only. Doing this will reduce the execution of Test script in working hours.

               If you want to schedule an execution of Script/Code in midnight on every day or in a week without executing that script explicitly. In that scenario it is very much important.

Steps to Do:

  • Open an Eclipse Select Java project Give any name and add external references under Libraries tab.
  • Create any package under "src" folder.
  • Create a single/multiple  classes under that package (one class should have main method).
  • Write code in class/classes.
  • Run the class which having main method at least single time.

Export executable .Jar file 

  • Select Respective project and right click on it.
  • Select Export option from list.
  • Select/type Runnable JAR file from select and export destination.
  • click on Next button
  • Launch Configuration: select the file in your project which has main method(start point for execution).
  • Click on Browse button and Select Export Destination path where executable Jar will reside & Give name. In My case I Have given name as Run.jar
      •  In my case I Will select Export Destination path as:  E:\Avinash
      • Path becomes: E:\Avinash\Run.jar
  • Click on Finish. 

 

Important Considerations:

In My case my Java is installed on this path :
                                      JDK: D:\Program Files\Java\jdk1.8.0_31\bin
                                      JRE: D:\Program Files\Java\jre1.8.0_51\bin
                     
                                      Exceutable jar: E:\Avinash\Run.jar

Windows Task Scheduler:

GO to Start menu -> All programs -> Accessories -> System Tolls -> Task Scheduler


1- Create a Basic Task 

Give name as: RunJarFile

Description: RunJarFile





2- Trigger:

Select radio button as Run One Time.
                                                      Wants to execute this Jar file only one time.




3- Action:

Select Start a Program option from below.



4- Finish:


Finally Select finish button & Enjoy.

CLASSPATH

D:\Avinash\BatchFile\bin\batch;D:\Program Files\Java\jre1.8.0_51\lib;D:\Program Files\Java\jdk1.8.0_31\lib;E:\Avinashh;


JAVA_HOME

D:\Program Files\Java\jre1.8.0_31;D:\Program Files\Java\jdk1.8.0_31\bin;

PATH

D:\Users\General\Downloads\IEDriverServer_Win32_2.44.0\IEDriverServer.exe;D:\Program Files\Java\jdk1.8.0_31\bin;G:\Java\JUnit\junit_4_10_jar\junit-4.10.jar;E:\Avinashh