Reputation: 8620
Is there a way to detect the installed java on various different Linux distributions? With Windows you could use the JAVA_HOME or the registry for that, but Linux? Can it be also detected if this is JDK, JRE, 32 or 64 bit?
REPHRASE: If I need 64-bit JDK on Linux, how do I programatically check that it is present and inform the user that he has some other java instead?
Upvotes: 4
Views: 6299
Reputation: 6656
There are many answers here helping you to check if Java is installed. If this is the case you can get more information programatically. SystemUtils of commons-lang
gives you many information about the Java version actually running.
Upvotes: 0
Reputation: 4210
To see the file called by the java
command use which java
, although this will often be just a symlink to the real executable, such as /usr/bin/java
. This works across all distros as far as I know.
On some Linux distros you can use update-alternatives --display java
(possibly with sudo
) to see a list of all the java executables installed on your system, and it will also tell you which one the symlink points to. You can switch between them by using the --config
option instead.
Upvotes: 1
Reputation: 115328
No unified way. You can use JAVA_HOME env. variable but it is not defined on all machines.
But there is a "common" way like ls /usr/java/*/bin/java | tail -1
.
This should give in most cases you the latest version.
Upvotes: 1
Reputation: 8228
You can always use java -version
.
This works on all platforms, but make sure that Java is included in the system PATH variable.
Upvotes: 5