How To stop an Executed Jar file
Asked Answered
B

11

35

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.

Benign answered 18/6, 2013 at 9:9 Comment(3)
Question isn't clear. Could you elaborate?Ribband
It will appear as "java" or "javaw".Araroba
are you using a jframe?Steinbach
C
41

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.

Consubstantiate answered 12/2, 2014 at 19:7 Comment(0)
F
27

Find the process id by jps command & and kill them by taskkill command.

Note that "-f" is required with taskkill or it may just send a termination signal not actually terminating it.

enter image description here

Foulness answered 3/4, 2016 at 8:8 Comment(0)
C
10

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.

Cleancut answered 18/6, 2013 at 9:14 Comment(2)
You can display PIDs in the task manager. View > Choose columns > PIDNasya
@Nasya jps is for java processes. It will show you only java processes. It is more convenient as you need not to search your process in a big list of processes as in task managerCleancut
B
8

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

Bryson answered 18/6, 2013 at 9:12 Comment(1)
oh, but what if i dont want to stop java?, i just want to stop that current processBenign
J
4

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

Jowl answered 18/6, 2013 at 9:21 Comment(1)
In my humble opinion, this is the best answer posted. I hate the idea of having to kill the entire java.exe process and until I read this answer, I thought that was the only way. I had always wondered why there was not a Task Manager-like interface for managing running jars, so I am glad to hear that there actually is one! Thank you for providing this answer, cproinger.Corin
N
3

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?

Nasya answered 18/6, 2013 at 9:18 Comment(0)
A
3

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
Abbeyabbi answered 18/9, 2017 at 10:22 Comment(0)
A
2

If you run the JAR file By command line and it is running yet. Press,
In Windows:
• Ctrl+C: shuts down the process, (it might be needed administrator privilege)
In Linux:
• Ctrl+ C : politely ask the process to shut down now.
• Ctrl+ \ : mercilessly kill the process that is currently in the foregroun.

Allurement answered 16/3, 2021 at 12:57 Comment(1)
What about Mac OS?Imco
D
0

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

Daphie answered 18/6, 2013 at 9:16 Comment(0)
S
0

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/

Steinbach answered 18/6, 2013 at 9:21 Comment(0)
N
0

This is probably the easiest way to kill the process with no external dependencies (jps or anything).

wmic Path win32_process Where "CommandLine Like '%YourJarName.jar%'" Call Terminate

via How can we stop a running java process through Windows cmd?

Narcisanarcissism answered 3/8, 2021 at 15:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.