Start & Stop Runnable Jar file without CMD

Hi!

To start and stop the runnable jar file in CMD is little bit complex if you are not use UI. In this chapter i will show you how to start and stop runnable Jar file by using bat files.

we need to create 3 bat files as follow

  1. start.bat --> which carrying command to start the jar file
  2. stop.bat --> which carrying command to stop the jar file
  3. run.bat  --> which can control the jar file
start.bat
please open the notepad, copy and paste the below commands and save as start.bat

@ECHO OFF
call run.bat start

stop.bat
please open the notepad, copy and paste the below commands and save as stop.bat


@ECHO OFF
call run.bat stop

run.bat
The run.bat file contains the information about your jar file. Please replace "nameofyourjar" into your jar file name wherever you find.

@ECHO OFF
IF "%1"=="start" (
    ECHO start nameofyourjar
    start "nameofyourjar" java -jar -Dspring.profiles.active=prod nameofyourjar.jar
) ELSE IF "%1"=="stop" (
    ECHO stop nameofyourjar
    TASKKILL /FI "WINDOWTITLE eq nameofyourjar"
) ELSE (
    ECHO please, use "run.bat start" or "run.bat stop"
)
pause


Way to use IT:

  • Keep everything inside a folder along with your jar file.
  • Double click start.bat to start the jar file and double click stop.bat to stop the jar file at anytime.


Thanks,
SelvaRaj

Comments