Enforcing Java minimum version to run with "java -version:<value>" doesn't work on Windows

Viewed 13812

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.

2 Answers
Related