Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

How to Create and execute Runnable JAR file for Java Project from command Prompt/Batch file

In this article, we will discuss steps to create an executable JAR file from a java project. This can be useful for our selenium Project. We are using Eclipse IDE for illustrating the example.


Prerequisite – It is assumed a java project is created.


Steps to create an executable jar file:


 Define the Run Configuration for execution

1.       Navigate to Run>Run Configuration for the Project.

2.       Select Java Application  and click on New launch configuration

3.       Provide the name to configuration and provide the main lass name to run.

4.       You can also define default argument for the execution.

5.       Save the configuration


Creating run configuration
Creating run configuration

 

Export the Project as executable Jar file


1.       Click on Project>Export

2.       Select export destination as Java>Runnable JAR files


Exporting as runnable JAR file
Exporting as runnable JAR file

3.       Select Run Configuration as one defined in step A.


Providing export location and launch configuration
Providing export location and launch configuration

4.       Provide export destination

5.       Click on finish


Run the executable JAR file 


 Through command prompt.


1.       Open command prompt

2.       Navigate to folder in which JAR file is saved.

3.       Run the following command  java -jar driverJAR.jar where driverJAR.jar is the name of JAR file



Double clicking on a batch file 


1.       Create a new text file in the same location as the JAR file.

2.       Rename the file as test.bat, thus creating a batch file.

3.       Add following content in the bat file

@echo "this is for testing the jar file"

java -jar testingJAR.jar

pause


4.       Save the file.

5.       Double click the file, it will run the jar file 



1 comment:

  1. Selenium |Training|Job Support|+91-741-626-7887 Selenium a Web based automation tool that automates anything and everything available on a Web page.   http://laymanlearning.com/selenium-training/ --- Send Enquiry --- hr@laymanlearning.com

    ReplyDelete