How To stop an Executed Jar file

2020-05-30 06:46发布

问题:

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 , i have tried TASKKILL but it also doesnt work for me.

回答1:

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.



回答2:

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.



回答3:

Did you try to kill the java.exe processes in the taskmanager? It should stop then.



回答4:

You can identify the process in taskmanager by looking for "java" or "javaw" processes. The problem will be in case you are running more than one java processes. If you are able to identify your process, simply kill/end it.

Other way around:

Run

jps -lv

which shows PIDs and command lines of all running Java processes. Determine PID of the task you want to kill. Then use command:

taskkill /PID <pid>

to kill the your jar process.



回答5:

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?



回答6:

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



回答7:

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


回答8:

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



回答9:

if you are using a jframe and you want your application to stop when you click the "X":

here's a tutorial: http://tips4java.wordpress.com/2009/05/01/closing-an-application/