3

I created a web project used spring boot and deployed it in remote server, and it's default JDK is

 echo $JAVA_HOME
/usr/local/jdk1.7.0_72

because I used java 8 in my project, so before starting my project, I explicitly exec below command

 export JAVA_HOME="/usr/local/jdk1.8.0_65"

then start my project

./myapp.jar

but when I exec below command

java -version
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)

I am a little confused, I'm not sure which jdk version my project actually used? That is there is a java process

jps -l
17429 /var/myapp.jar

How do I know which java version it is used?

Thanks @frant.hartm

# ps aux | grep 17429
root     17429  0.4  6.7 5995260 1104984 pts/13 Sl  19:16   0:29 /usr/local/jdk1.8.0_65/bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -Dserver.port=8081 -jar /var/myapp.jar

# jcmd 17429 VM.version
17429:
Java HotSpot(TM) 64-Bit Server VM version 25.65-b01
JDK 8.0_65

2 Answers 2

5

Use jcmd:

jcmd process_id VM.version

$ jcmd 9619 VM.version
9619:
Java HotSpot(TM) 64-Bit Server VM version 24.80-b11
JDK 7.0_80

Alternatively, you can use ps to find out which java binary was used:

ps aux | grep 9619
user  9619  0.0  0.5 4031224 82480 ?       Sl   12:31   0:01 /usr/lib/jvm/java-7-oracle/bin/java -cp /usr/lib/jvm
Sign up to request clarification or add additional context in comments.

Comments

0

If you execute which java, it will give you which java binary is used by default on your OS.

If you want to run your application with Java 8 and leave default location unchanged just run:

/usr/local/jdk1.8.0_65/bin/java ./myapp.jar

2 Comments

thanks but I want to know if eixst some jvm tool e.g. jstack jmap could help you to know the java version of a java process
On most linux distributions that have some kind of "alternatives" system (like Ubuntu) this will point to a symbolic link (e.g. /usr/bin/java -> /etc/alternatives/java, /etc/alternatives/java -> /usr/lib/jvm/java-8-oracle/jre/bin/java)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.