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
Perhaps something like:
The method I ended up using is:
It will work correctly even if JAVA_TOOL_OPTIONS is set to something due to filtering done by grep.
You can obtain java version via:
it will give you
16
for java like1.6.0_13
and15
for version like1.5.0_17
.So you can easily compare it in shell:
UPDATE: This code should work fine with openjdk and JAVA_TOOL_OPTIONS as mentioned in comments.
You can issue
java -version
and read & parse the outputI had a similar problem, I wanted to check which version of java was installed to perform two types of application launches. The following code has solved my problem
source
I hope to be proved helpful
A combination of different answers:
7
for Java 7 and8
for Java 8