It feels like a dumb question to ask, but i cant seem to figure it out. when i run a *.jar file on windows it doesnt apears in the taskmanager processes. how can i terminate it
On Linux
ps -ef | grep java
It will show u a list of processes out of which one will be your executable jar. Just kill that process by its process id.
sudo kill -9 <pid>
Is there any way to do this from the java code of the same jar file. Like killing itself once process completed.
In windows task manager you will see process called "java.exe". Kill that process your application will get stop.
To know the process first go to applications in task manager and then go to process by selecting that application. It will lead you to exact process of that application.
Regards, Jaynil
spring boot start/stop sample (on Windows OS).
start.bat
@ECHO OFF
call run.bat start
stop.bat:
@ECHO OFF
call run.bat stop
run.bat
@ECHO OFF
IF "%1"=="start" (
ECHO start your app name
start "yourappname" java -jar -Dspring.profiles.active=prod yourappname-0.0.1.jar
) ELSE IF "%1"=="stop" (
ECHO stop your app name
TASKKILL /FI "WINDOWTITLE eq yourappname"
) ELSE (
ECHO please, use "run.bat start" or "run.bat stop"
)
pause
you could open jvisualvm to see the running java-processes. the process-id is displayed there. now open the task-manager go to the processes tab and add the process-id column to be displayed. now you can select the right java.exe or javaw.exe to kill
As everyone stated it is either java or javaw process. The problem is when you're running multiple apps like that. One workaround might be naming the process differently as stated in:
How can I set the process name for a Java-program?
Find the process id by jps
command & and kill them by taskkill
command.
Note that "-f
" is required with taskkill
or it may just sent a termination signal not actually terminating it.