10

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.

Community
  • 1
  • 1
crAlexander
  • 376
  • 1
  • 2
  • 12

4 Answers4

5

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

Sireesh Vattikuti
  • 1,180
  • 1
  • 9
  • 21
  • Hey man be more specific.Run this code from cmd? If it's easy for you give some more iformation in the example.It will be usefull a link.What it aux and grep? – crAlexander Feb 28 '15 at 18:38
  • @crAlex This is for a *nix system, not windows. – DMP Feb 28 '15 at 18:43
3

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.

DMP
  • 973
  • 1
  • 7
  • 13
  • @crAlex Yes this is done from cmd and uses built it tools. There is no 100% platform independent solution that uses all built in tools. You can combine the two answers putting my answer in a batch file for windows and the other answer in a shell script for every other operating system. – DMP Feb 28 '15 at 19:05
  • If it is easy for you give me a full example.ImageName = full path of jar? and what is eq?Thanks.. – crAlexander Feb 28 '15 at 19:08
  • @crAlex What I did was use tasklist(lists all running programs) with a few options: /v means verbose so you can see some extra info. /fi means filter, the quotes are the filter. "IMAGENAME eq java.exe" is the filter, it checks the image name or program name to see if it is equal(eq) to java, which is what you are looking for. Put that together: list all running programs with extra verbosity and only if the program is Java. – DMP Feb 28 '15 at 19:13
  • i try your code but i get (Not tasks are running which match the specified criteria) I run the same time one jar file to be soore that at least one jar file is running under java.exe.Why this happens? – crAlexander Mar 05 '15 at 00:55
0

To test this, pick a .exe file you see running in Task Manager and test out the cmd line.

If you see the following output :

No tasks are running which match the specified criteria

That means there is no task running equal to java.exe.

Besworks
  • 4,123
  • 1
  • 18
  • 34
MaximoC
  • 1
  • 1
0

Use the following command:

ps aux | grep java
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103