I'm playing around with some microservices and running them on my laptop, simply assigning each micro-service a new port. The problem is that I'd like to restart one of them I have to close them all because in the operating system the processes are all called java. And although I sometime can guess that the last started have the highest pid etc is isn't exacly a safe bet...
So, is there a way to start a java-application and assign it a name in the operating system? Perhaps something like
java --Dos.name MyFirstService -jar MyJar.jar.
You can also find the PID of a java program with the task manager. You enable the PID and Command Line columns View -> Select Columns and are then able to find the right process.
On Linux, you can view processes with the ps command. It is the simplest way to view the running processes on your system. You can use the ps command to view running Java processes on a system also by piping output to grep .
To get a list of Java processes running on a machine, use either the ps command or, if the JVM processes are not running in a separate docker instance, the jps command.
Under Windows, you can't (unless installing some kind of posix subsystem).
Under Linux, you could use exec
command with the -a "newName"
option to alias the process you wish to spawn.
Like
exec -a "myJar" /path/to/java -jar /path/to/jar.jar
If you need to be able to differentiate between different java programs you can use the jps command that gives you a list of all java processes and running your program with
java -Dname=myFirstService -cp myFirstService.jar some.client.main.MyFirstService
then if you do a:
jps -v
You will see your process correctly.
If you need to change the process name at the OS level I recommend you use http://launch4j.sourceforge.net/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With