6

I get the following error while trying to compile or run everything that has to do with java or javac:

Error occurred during initialization of VM
java/lang/ClassNotFoundException: error in opening JAR file <Zip file open error> /usr/lib/jvm/java-8-oracle/jre/lib/rt.jar

I've read here that i should uninstall and install again JDK, here it is written that I should know which version of java I have installed on my pc in order to uninstall-it.

To check the version installed i run java -version but i get the error mentioned above, how can i check my java version without that command?

I know that i have installed java 8 but i don't know precisely which version it is.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
Zeno Raiser
  • 485
  • 1
  • 6
  • 18
  • "I know that i have installed java 8 but i don't know precisely which version it is." Installed how? – muru Apr 13 '18 at 12:14
  • I have about 35 different JREs installed in various nonstandard paths on a Linux server, but I cannot execute java -version as they are owned by other users. I also cannot run apt and most system tools (I do not have su). However I do have read access to each of the "java" binaries. Is there a way to find the java version from the binary itself? – Kristopher Noronha Dec 30 '21 at 11:45

4 Answers4

6

To show what version of Java is installed without running java -version, open the terminal and type:

apt policy openjdk-* oracle-java* 

A small part of the results of apt policy openjdk-* looks like this:

openjdk-7-jre-lib:
  Installed: (none)
  Candidate: (none)
  Version table:
openjdk-8-jdk:
  Installed: 8u162-b12-0ubuntu0.16.04.2
  Candidate: 8u162-b12-0ubuntu0.16.04.2

Search for sections that contain either openjdk-*-jre , openjdk-*-jdk or oracle-java* where the wildcard * character can be a Java version number like 6, 7, 8 or 9.

karel
  • 114,770
5

You can discover the full path of the default java executable with:

readlink -f "$(which java)"

All (sane) Java packages or bundles that I know use installation path names that include the vendor name and major version number which would answer your question. E. g. on my system

$ readlink -f "$(which java)"
/usr/lib/jvm/java-9-openjdk-amd64/bin/java

tells me that the default Java installation is OpenJDK 9.

David Foerster
  • 36,264
  • 56
  • 94
  • 147
3

You could also try:

dpkg -l | egrep -i 'jre|java|jdk'
David Foerster
  • 36,264
  • 56
  • 94
  • 147
muclux
  • 5,154
2

You can use this command for checking your java version:

update-alternatives --config java
Campa
  • 983
  • 7
    Wouldn't update-alternatives --display java be simpler and better since OP only wants to “display” available Java versions, not change the default? That wouldn't even require sudo. – David Foerster Apr 13 '18 at 10:47