How to create a Batch file(.bat) using a runnable jar file in java

Let’s say that you have created some java classes via Eclipse IDE.First choose one or more classes you want to run.

Right click on a class and choose export.

login-export

Then the following window will appear and choose “Runnable JAR file” menu item.

two

Click next and following window will appear.

three

Select the class you are going to export as a runnable jar under Launch configuration drop down.

Select “Package required libraries into generated JAR” under Library handling.

Click on the browse button in the Export destination drop down and select a location to save the jar file and at the same time give a name (ex:test) for the jar file too.

four

five

Then click on finish and if you go to the location where you selected in the above dialog boxes, the jar file will be there.(ex: test.jar)

Just double click on it and it will execute your program.

Also you can execute this via a batch file.Take a notepad and write down the code below and save it as .bat extension.

start javaw -jar test.jar 

(test.jar is the name of the runnable jar file you created)

Then double click and run the batch file.It will also execute your program.

Leave a comment