I want to enforce the minimum version of JVM my application should run on to 1.6 or greater (i.e. 1.6+). My understanding is that you can do this using the "-version:" command line argument. I tried it, and it seemed to work fine under Linux but not under Windows.
LINUX
I have a JDK version 1.6.0_21 installed on a Linux machine. The $JAVA_HOME and $PATH environment variables have been set to what they should be.
I ran the following:
$ java -version:1.6+ -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)
$ java -version:1.5+ -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b16, mixed mode)
$ java -version:1.7+ -version
Unable to locate JRE meeting specification "1.7+"
All seemed to be expected. "version:1.6+" and "version:1.5+" should work because I have a JDK 1.6.0_21 installed, and "version:1.7+" shouldn't because I don't have a JDK 1.7 installed.
WINDOWS
I have the same JDK version 1.6.0_21 installed on a Windows machine (Windows 7 to be more specific). The %JAVA_HOME% and %PATH% environment variables have been set to what they should be.
I ran the following:
$ java -version:1.6+ -version
Unable to locate JRE meeting specification "1.6+"
$ java -version:1.5+ -version
Unable to locate JRE meeting specification "1.5+"
$ java -version:1.7+ -version
Unable to locate JRE meeting specification "1.7+"
I got an error for each execution.
Can anyone explain why does the same command line argument work on Linux, but not on Windows? Is this a feature or a bug?
What can I do to fix/work around it? As much as possible I want to have the same command line arguments applied on both Linux and Windows, so I don't have to specify a different "-version:" argument for Linux and another different one for Windows.
Thanks.
Go to Environment Variables in your windows machine. In User Variables : Make sure to set - Your user variable "JAVA_HOME" value to "C:\Program Files\Java\jdk-xxxx\bin" where "jdk-xxx" is the version of your jdk. In System Variable : - Add same "C:\Program Files\Java\jdk-xxxx\bin" value to "Path" variable.
Downloading the JRE InstallerThe JRE Installer is located on the Java SE Runtime Environment 10 Downloads page. In a browser, go to the Java SE Runtime Environment 10 Downloads page. The following JRE installers are available for you to download: Windows Offline: jre-10.
The JDK and JRE versions can be different on the same computer. Multiple JDK and JRE versions are allowed on the same computer; it is better to find out which version is configured in the system classpath to run or compile the Java program.
- Can anyone explain why does the same command line argument work on Linux, but not on Windows? Is this a feature or a bug?
I don't think it is related to Linux vs. Windows, rather an issue with particular distributions - I can run this just fine on Windows with the Oracle JDK now, i.e. the successor of the Sun JDK (both via PowerShell or CMD):
PS> java -version:1.7+ -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
On the contrary, it fails for me on Ubuntu 12.04 LTS with OpenJDK:
$ java -version
java version "1.7.0_51"
OpenJDK Runtime Environment (IcedTea 2.4.4) (7u51-2.4.4-0ubuntu0.12.04.2)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)
$ java -version:1.7+ -version
Error: Unable to locate JRE meeting specification "1.7+"
A short search reveals the following somewhat inconclusive issues:
I've confirmed this to still be broken with OpenJDK 6/7 on Ubuntu 13.10 and also on Amazon Linux 2013.09.2, so I suggest to experiment with a different OpenJDK distribution or JDK vendor, in case this issue is prevalent - it's definitely an odd issue, esp. given OpenJDK is meanwhile the official Java SE 7 Reference Implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With