Take the 2-minute tour ×

I am a newbie in cmd, so please allow me to ask a stupid question: How can we stop a running java process through windows cmd?

For example, if we start jetty(a mini web server) with the following cmd:

start javaw -jar start.jar

How do we find the process and stop it later?

Obviously the following cmd does not work:

stop javaw -jar start.jar
share|improve this question
Did you try Ctrl + C or Ctrl + Break? –  Frank Bollack Apr 15 '10 at 9:00
yes, but can I build a .bat file to stop it with Ctrl + C or Ctrl + Break? –  Winston Chen Apr 15 '10 at 9:05
Maybe check the taskkill command. It has many options for choosing the process to kill: by process id, by name pattern, by owning user, etc. But I recommend first looking for a standard, less violent way of closing the specific application (servers usually have some kind of "stop" command) –  Eyal Schneider Apr 15 '10 at 9:10
Do you know the process name? If you do, you can build a .bat file that uses the taskkill command: microsoft.com/resources/documentation/windows/xp/all/proddocs/… (for example, taskkill /im notepad.exe). –  IVlad Apr 15 '10 at 9:10
hey, guys, thank you all but I cannot vote you guys up or mark correct answer here. If you guys don't mind, please answer it. –  Winston Chen Apr 15 '10 at 9:20

6 Answers 6

up vote 5 down vote accepted

It is rather messy but you need to do something like the following:

START "do something window" dir
FOR /F "tokens=2" %I in ('TASKLIST /NH /FI "WINDOWTITLE eq do something window"' ) DO SET PID=%I

Found this on this page.

(This kind of thing is much easier if you have a UNIX / LINUX system ... or if you run Cygwin or similar on Windows.)

share|improve this answer
PowerShell also makes this trivial. –  Joey Apr 18 '10 at 8:39

I like this one.

wmic process where "name like '%java%'" delete

You can actually kill a process on a remote machine the same way.

wmic /node:computername /user:adminuser /password:password process where "name like '%java%'" delete

wmic is awesome!

share|improve this answer

When I ran taskkill to stop the javaw.exe process it would say it had terminated but remained running. The jqs process (java qucikstart) needs to be stopped also. Running this batch file took care of the issue.

taskkill /f /im jqs.exe
taskkill /f /im javaw.exe
taskkill /f /im java.exe
share|improve this answer

Normally I don't have that many Java processes open so

taskkill /im javaw.exe


taskkill /im java.exe

should suffice. This will kill all instances of Java, though.

share|improve this answer

FOR /F "tokens=1,2 delims= " %%G IN ('jps -l') DO IF %%H=name.for.the.application.main.Class taskkill /F /PID %%G

name.for.the.application.main.Class - replace this to your application's main class

share|improve this answer

start javaw -DSTOP.PORT=8079 -DSTOP.KEY=secret -jar start.jar

start javaw -DSTOP.PORT=8079 -DSTOP.KEY=secret -jar start.jar --stop

share|improve this answer

Your Answer


