How can i find out default options of a jvm when i start some jar file ? Except those options, which are specified in a command, like java -jar somefile.jar -XX:MaxPermSize=256m. So, what i need to know is there any other hided options of a jvm which i can find ?
One of the way to do that is to search for a java process by running
ps -ef | grep java
which will show you all the JVM params.
Note: this will work only on Linux and probably MacOS
Related
I need to execute a jar file on HP-UX that I am not supposed to modify.
I unpacked it using jd-gui and found out that I am failing cause in java there is a condition to check the os, leading to different directions for win, macos, freebds, openbds, gnu and so on.
I am quite sure everything would work if I would be able to make my unix command line reply freebds or openbds to the java call
System.getProperty("os.name")
once executed from a jar file like:
java -jar myjar.jar
is there a way to achieve this? some kind of compatibility mode or a way to preset that parameter.
You can use the -D switch to specify system properties. In my experiment this (unexpectedly) even worked with pre-defined ones like os.name. Therefore this should work:
java -Dos.name=linux -jar myjar.jar
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.
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
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.
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.
Use the following command:
ps aux | grep java
I'm trying to determine the Tomcat install directory when it is started from startup.bat in Windows.
It is easy enough to determine where tomcat7.exe is running when Tomcat is running as a service, but I'm not sure how to do it when it's started with the script. I know java is running when Tomcat is started from the script, but the executable path is for the java jre. Is there something I can do to find where catalina is running based on java?
Assuming you know the location of startup.bat, then just go two folders above and you're done.
Assuming you only have a shortcut to this file, then you would need to retrieve a list of processes explaining the application and the location of the files they're using, similar like ps aux command from Unix based OSes. Fortunately, Windows have such thing as well. From this great Q/A: Is there a command in Windows like ps -aux in UNIX?, more specifically, this answer, the way to find the location of tomcat in Windows is to execute the wmic application (through CMD if you want) and write process command, this will provide a list of the current applications running and their parameters. For example, I initialized Tomcat from startup.bat file and got this result using the commands above (single line):
java.exe "C:\Program Files\Java\jdk1.7.0_40\bin\java" -Djava.util.logging.config.file="<TOMCAT_HOME>\conf\logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs="<TOMCAT_HOME>\endorsed" -classpath "<TOMCAT_HOME>\bin\bootstrap.jar;<TOMCAT_HOME>\bin\tomcat-juli.jar" -Dcatalina.base="<TOMCAT_HOME>" -Dcatalina.home="<TOMCAT_HOME>" -Djava.io.tmpdir="<TOMCAT_HOME>\temp" org.apache.catalina.startup.Bootstrap start
Here's the same result but splitted in several lines to ease readability:
java.exe "C:\Program Files\Java\jdk1.7.0_40\bin\java"
-Djava.util.logging.config.file="<TOMCAT_HOME>\conf\logging.properties"
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.endorsed.dirs="<TOMCAT_HOME>\endorsed"
-classpath "<TOMCAT_HOME>\bin\bootstrap.jar;<TOMCAT_HOME>\bin\tomcat-juli.jar"
-Dcatalina.base="<TOMCAT_HOME>"
-Dcatalina.home="<TOMCAT_HOME>"
-Djava.io.tmpdir="<TOMCAT_HOME>\temp"
org.apache.catalina.startup.Bootstrap start
Note: I've replaced the real path by <TOMCAT_HOME> in the results from above.
TL;DR do this:
Open cmd
Execute wmic
Execute process
Wait few secs and search java.exe and the arguments containing Tomcat jars.
Since you explicitly mentioned *.bat and Windows here is your answer.
1.Most tomcat application comes as a zip instead as msi/exe . The place where you extract is actually its locations . You start the application by clicking startup.bat file
2.Open the bat file with notepad . You will also find the relative path of the application.
3.Look for the path variables .
Hope this information helps
Im running a jar file as part of a large web app. The majority of the app is written in php, but there is one large .jar file that it interacts with. To start this jar file I use ssh to connect to the server, navigate to the directory and run it by calling:
java -jar file_name.jar
If I want to turn off this file, what's the ssh command for that ?
While agreeing with other comments and answers, I'd like to point out the oft forgotten jps tool packaged with JDK's
anders#localhost:~$ jps -v
15688 Jps -Dapplication.home=/usr/lib/jvm/java-7-oracle -Xms8m
which lists all running Java processes on the host (might want to sudo if the process wasn't started by your login user).
So, with some command line magic such as
kill -9 `jps -v | grep file_name.jar | awk {'print $1'}`
you would achieve your stated purpose.
Cheers,
If you do:
ps aux
or something similar (see man ps for the many different possible commands) you should be able to find the PID of the java process (might be difficult if there are many java processes running*).
Then do:
kill PID
If that doesn't work, try:
kill -9 PID
But this will not give the process a chance to shut down cleanly.
*) The reason this might be difficult with many java processes running, is that on some OS's, Java versions, etc, the process name might simply be "java", which makes it hard to distinguish them.
Update: Or you can use pgrep -lf file_name.jar to get the PID easier.
See https://linux.die.net/man/1/pgrep
I'm writing an application that leverages jsvc to start up a Java service as a daemon. I need to use something like jsvc because my application utilizes ports under 1024 and yet I'd really like to not run it as root so that created files are owned by another user. I'd also like to keep dependencies and configuration to a minimum so that all the client needs is a JVM and the jsvc binary installed.
However, it seems that jsvc has one major catch; it can't detect the home folder of Java on a given Unix operating system, which is quite frustrating:
$ ./startup.sh
Cannot locate Java home
I have been able to work around the issue on Ubuntu at least by manually setting the JVM home directory:
jsvc ... -home /usr/lib/jvm/default-java/ ...
Is there any way to determine the Java home directory dynamically from a Bash script so I can make this work across most Unixes/Linuxes? I'd be able to sleep much better at night doing something like:
JAVA_HOME="$( ... )"
jsvc ... -home "$JAVA_HOME" ...
...rather than hard-coding for each individual operating system. Is there a way that, given a java binary, I can find the home directory of its JVM/JRE?
Not sure if this works across *nixes, but found this solution:
JAVA_HOME="$( readlink -f "$( which java )" | sed "s:bin/.*$::" )"
I've tested it on Ubuntu and it works, however it does not work for OSX.
My solution was compiling the native linux source as the main jsvc page says in
http://commons.apache.org/proper/commons-daemon//jsvc.html
Here is my step by step procedure
Download www.fightrice.com/mirrors/apache/commons/daemon/source/commons-daemon-1.0.13-src.tar.gz
Once you extract the file then go to ...../commons-daemon-1.0.13-src/src/native/unix
in terminal as a root do the following:
$ support/buildconf.sh
$ ./configure --with-java=/usr/lib/jvm/default-java
$ make
test generated jsvc binary app
$ ./jsvc -help
It works! cleanly.
Use dirname and which commands to find Java's bin directory:
echo `dirname \`which java\``
JAVA_HOME=`dirname \`which java\``
... Only works if Java is already on the $PATH.
One other way is :
type -p java
Expect this to return the correct JAVA installation folder.