When executing a Java application the process name given to it is usually java.exe
or javaw.exe
. But how can I make it be called by the name of my
Assuming that what you are really after is a way to terminate the correct the correct process later on, then an alternative solution is this:
Run ps -ef | grep java
and you should get a listing that looks something like this:
mruser 7518 7505 4 11:37 pts/3 00:00:00 /usr/bin/java -classpath MRD3030_Linked.jar peralex.MyApp
Then pkill -f peralex.MyApp
will kill the correct process.
I needed a workaround for this in windows to enable me to stop particular java processes. I've settled on using a .bat file to run the different .jar files, with the first line of the .bat file being TITLE "Name to give the cmd window", then when I look through the different cmd windows I can see which on is the one I want to stop and Ctrl-C via that cmd window.
Not all flavors of exec support the -a flag. If yours doesn't, the argv0 program does something similar.
This is specific to Windows.
I was facing the same issue where I have to kill the specific java program using taskkill. When I run the java program, tasklist was showing the same program with Image name set as java.exe. But killing it using taskkill /F java.exe will stop all other java applications other than intended one which is not required.
So I run the same java program using:
start "MyProgramName" java java-program..
Here start command will open a new window and run the java program with window's title set to MyProgramName.
Now to kil this java-program use the following taskkill command:
taskkill /fi "MyProgramName"
Your Java program will be killed only. Rest will be unaffected.