"java -version" not working in command prompt

Windows 2k8 R2 server- For both java [-option] or %JAVA_HOME% to work in the command line you need the following:

In Control Panel->System and Security->System->Advanced system setting->Advanced->Environment Variables->System Variables

Edit the Path variable and add a ";" after the last value and add the the path to the Java bin directory: e.g.- C:\Progra~2\Java\jre6\bin\

Add the JAVA_HOME Variable with the value set to the path for the java executable: e.g.- C:\Progra~2\Java\jre6\bin\java.exe


Java is typically installed (on Windows) as C:\Program Files\Java\jdk<version>

That installation directory has a subdirectory bin which you need to append to your PATH environment variable via the control panel. Then, the commands like java, javac etc. will be available on the command line.

BTW, the same is true for Grails.


Press simultaneously the "windows" and "pause" buttons on your keyboard, this will bring up the System Preferences dialog. In the Advanced tab, find Environment Variables.

Then, in the User (upper) section, create or update the following two variables :

  • JAVA_HOME = where you put your JDK, eg. C:/Java/SDK
  • PATH = %JAVA_HOME%/bin

Close the dialogs.

Then, in a new command-line console, try "javac -version" and see if it's detected. It's important that you use a new console, because environment variables are read only when the console is launched.

Tags:

Java

Grails