2

Run the following in Windows:

java -version:1.5+

echo %ERRORLEVEL%

If you run it with Java 5 or Java 6, you'll get an exit code of 0 meaning success (meaning the version is at least 1.5).

If you run it with Java 7, you get exit code 1, which means failure.

Anyone run into this and know what happened?

2
  • The only solution I've found so far is to append " -?" so it becomes: java -version:1.5+ -? This fixes the errorlevel issues but causes the syntax to appear. Commented Feb 26, 2012 at 15:10
  • To resolve the syntax appearance issue, use "2> nul" at the end. Commented Feb 26, 2012 at 15:11

1 Answer 1

1

-version:<value> syntax is intended to request launcher to do something with specific version of JVM. I.e. run your Java application, or print version (-?). But target is not specified, and it is an error. Launcher prints usage and returns 1. Same as running plain java.exe without any parameters. I believe that behavior observed in previous releases is just a minor bug fixed in Java 7.

EDIT You could run java -version:1.5+ -version. This requests launcher check available VMs and print version (that is always successful operation). Less verbose than -? option.

The other option is create some stub class with main method that will do nothing. Then successful check will be completely silent. java -version:1.5+ your.stub.MainClass

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.