Wednesday, June 12, 2019

Stop and Start JAR file in background CMD on Windows using bat file

I share example how to execute JAR file in background or if you want execute command line in background on Windows.

Steps:

1. Create file start.bat and add next code.

@echo OFF
cd C:\path_your_jar
start javaw -jar your_jar.jar


2. Create file stop.bat and add next code. for example if you application up in the port 9000 then you find the port and PID and kill.

@ECHO OFF                                                                           
FOR /F "tokens=5" %%T IN ('netstat -a -n -o ^| findstr "9000" ') DO (
SET /A ProcessId=%%T) &GOTO SkipLine                                                 
:SkipLine                                                                           
echo ProcessId to kill = %ProcessId%
taskkill /f /pid %ProcessId%

or

if you want to find jar and to change the next line.

@ECHO OFF                                                                           
FOR /F "tokens=1" %%T IN ('jps -m ^| find "jar" ') DO (
SET /A ProcessId=%%T) &GOTO SkipLine                                                 
:SkipLine                                                                           
echo ProcessId to kill = %ProcessId%
taskkill /f /pid %ProcessId%

That is it.




No comments:

Post a Comment

Provisioning Cloud SQL with Private Service Connect Using Terraform & Accessing from Cloud Run with Spring Boot

In this post, we'll explore how to provision Cloud SQL instances with Private Service Connect (PSC) connectivity using Terraform and the...