Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop a java application?

Tags:

java

I have made a java application and have packed it into an executable jar file. Now a user can start that program from either of the following two ways:

  1. Start if from command prompt by executing the following command on the command prompt:

    java -jar "MyJar.jar"

  2. By double clicking on that jar file.

I want that my client would adopt second approach as it is much easier than the first approach. But the problem with second approach is how to stop application before it has finished?

It is a command-line application.

And no command prompt window appears when a user double clicks on the jar file. So in this case, Will Ctrl + c work?

like image 955
Yatendra Avatar asked Dec 01 '22 11:12

Yatendra


1 Answers

Stopping (exiting) the application should be inside the application. Whether it is command line or GUI based, the application developer should write code to exit it (For eg., in a command line application you might have something like Press 5 to exit, Press Esc to Exit etc) and in an application with a GUI, you will have to write code to exit when the window is closed, or an EXIT button (or others, depending on your application)

Ctrl + C is KILL the application. This is not a Normal exit. For apps with a GUI, the user would typically (in Windows) go to task manager and end the process (similar ways in other operating systems)

But these are abnormal exits - when the user wants to kill the app when, for instance, the application is no longer responding. Normal exits should be provided by the application (and therefore by the programmer - you)

like image 169
Nivas Avatar answered Dec 02 '22 23:12

Nivas