Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if a jar file is already running?

Tags:

java

jar

gps

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.

like image 201
crAlexander Avatar asked Feb 28 '15 18:02

crAlexander


People also ask

Is JAR file already compiled?

A . jar file contains compiled code (*. class files) and other data/resources related to that code. It enables you to bundle multiple files into a single archive file.

What happens when a JAR file is executed?

Most JAR files are simply containers for data that another program needs to run with Java; therefore you cannot run these files and nothing will happen when you double-click them. Similarly, most executable JAR files are downloaded as installation files to install applications or programs.

Are all jar files executable?

Jar files (Java ARchive files) can contain Java class files that will run when the jar is executed. A jar is an archiving format that not only stores directories and source files, but can be run as an executable as well.


2 Answers

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

like image 116
Sireesh Vattikuti Avatar answered Nov 04 '22 04:11

Sireesh Vattikuti


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.

like image 32
DMP Avatar answered Nov 04 '22 03:11

DMP