How to know if a jar file is already running?

2019-06-28 07:53发布

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.

标签: java jar gps
2条回答
兄弟一词,经得起流年.
2楼-- · 2019-06-28 07:56

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.

查看更多
太酷不给撩
3楼-- · 2019-06-28 07:59

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

查看更多
登录 后发表回答