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.
Subscribe to:
Posts (Atom)
Creating REST APIs with OpenAPI, Spring Boot 3.3.3, Java 21, and Jakarta
Introduction In today's software landscape, designing robust and scalable REST APIs is a crucial aspect of application development. Wit...
-
SAML V2.0 SAML version 2.0 was approved as an OASIS Standard in March 2005. Approved Errata for SAML V2.0 was last produced by the SSTC on 1...
-
Single Sign-On (SSO) is an authentication process that allows users to access multiple applications or services with a single set of login c...
-
Keycloak Keycloak is an open source identity and access management for modern applications and services, no need to deal with storing user...