How to know if a jar file is already running?

时光总嘲笑我的痴心妄想 提交于 2020-01-03 15:36:40

问题


After a research in google i found good answers like:

1)using jps or jps -l to get the jars running under JVM

OK with this answer but if the user has not java installed at all and i run my jar using for example a .bat file and a folder with java JRE.

Also gps function is experimental and only JDK contais it and not JRE.

2)Check if jar running from shell

I need a solution for this on windows platform.Although a platform indepedent solution is always prefferable.

Something more about jps(cause it is Platform Independent) I will appreciate an answer where you provide me a good solution with jps function.


回答1:


You can us ps and grep on a *nix system as described above. For windows you can do:

tasklist /v /FI "IMAGENAME eq java.exe"

This will get you a list of all the Java programs running. I don't think you can get much closer on Windows.




回答2:


use this command to check the jar is running or not.

ps aux | grep java

eg:

sys_name 7526 60.1 2.6 4474364 104092 pts/4 Sl+ 23:57 0:09 java -jar start.jar



来源:https://stackoverflow.com/questions/28785141/how-to-know-if-a-jar-file-is-already-running

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!