I tried java --version in the command line and I get :
Unrecognized option: --version
Error: Could not create the Java virtual machine
Error: A fatal exception has occurred. Program will exit.
Everything was working fine until I installed jre 7 (I had jdk 1.6 preinstalled ) So, I uninstalled the previous versions, restarted and then installed fresh jdk 7u5 windows i586.
Still I get the same problem. Can anyone help me with this?
I am unable to install and run maven for this reason.
3 Answers 3
You used two - marks. Try with one: java -version.
Update: Since Java 9 java and javac commands support both --version and -version.
Bonus:
As mentioned by Stephen C java --help states (at least in recent versions supporting --version) that
-version print product version to the error stream and exit --version print product version to the output stream and exit
This means that if you try to execute java -version programmatically, for instance via Process you will need to read its result from Process#getErrorStream() instead of Process#getOutputStream().
Such behavior can be also observed in other java options which have - and -- versions. For instance -h or -? or -help will print to error stream, while --help will print to output stream.
2 Comments
-version and --version. The former outputs to standard error, while the latter outputs to standard output ... as is the standard behavior for --version options on Linux, MacOS, etc. (This is mentioned by java --help ... at least on recent versions of Java that support the --version form.)java -version
This is the command to get the current installed version info
1 Comment
For me the following command works: java -version instead of this: java --version
java -helpprints out usage information; doing that would've given you the solution immediately.--help)