Link to home
Start Free TrialLog in
Avatar of De_Cisse
De_Cisse

asked on

Stop execution of jar

Is it possible to stop the execution of a .jar file using e.g. a .bat-file? If so, how can this be done?

If not, what is the appropriate way to stop the execution? I could use system.exit(), but how can I call this from an external procedure or pass arguments to a running java application?
ASKER CERTIFIED SOLUTION
Avatar of __geof__
__geof__
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you are running windows the much easier way is this batch command. This way it requires no modification of your Java code. It should stop all JARs running. You could run it in command prompt or run it in a .BAT file.
taskkill /F /IM java.exe

Open in new window

taskkill /F /IM java.exe will kill any JVM. You cannot be sure that you won't kill another application in addition to yours.

That is true, the solution using taskkill arbitrarily kills all Java VMs. This could create problems if you are also running java based programs such as Netbeans. For this reason this is not an elegant but a easy solution.
Avatar of De_Cisse
De_Cisse

ASKER

Superb way to control start and stop of an application. You can write a generic ClientApplication to stop whatever jar you want.