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.

解决方案

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/

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐