How can I check whether Java is available (in the PATH or via JAVA_HOME) from a bash script and make sure the version is at least 1.5?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I wrote a bash function that should work for JDK 9 and JDK 10.
This returns
8
for Java 8 ("1.8.0_151"
etc), and9
for Java 9 ("9-Debian"
etc), which should make it easier to do the further comparison.Using bashj, an extended bash version (https://sourceforge.net/projects/bashj/), you get a rather compact solution:
The answer is provided by an integrated JVM (in ~0.017'' execution time for the script , and ~0.004'' for the call itself).
I know this is a very old thread but this will still be of help to others.
To know whether you're running Java 5, 6 or 7, firstly type
java -version
.There will be a line in your output that looks similar to this: java version "1.7.0_55"
Then you use this table for converting the 'jargon' result to the version number.
1.7.0_55 is Java 7
1.6.0_75 is Java 6
1.5.0_65 is Java 5
Information taken from a page on the Oracle site
http://www.oracle.com/technetwork/java/javase/7u55-relnotes-2177812.html