How to find the process id that is running my Java Application

1.2k Views Asked by At

I know it's quite basic question but still I am not clear about it. When I am running my jar file in background in windows using below command using bat file:

start javaw -jar myApp.jar

It start the application in background but is there any way to check if it's running or how would i kill it if I want to.

In Linux We can do ps -ef| grep JarName and then we can call kill command.How to do the same in windows. tasklist command shows java.exe instead of jar name.

Regards,

1

There are 1 best solutions below

0
DuncG On BEST ANSWER

You could use jps to view current Java processes, then pass the output to taskkill. Call this script with the full package.Classname of the process to kill:

rem Run as killpid.cmd package.Classname 
@echo off
jps -l |findstr %1 > %TEMP%\pid.txt

echo FOUND:
type %TEMP%\pid.txt

for /f %%i in (%TEMP%\pid.txt) do taskkill /pid %%i