2

When i type javac in cmd it's not recognized , although i do have jdk 1.7installed and specified JAVA_HOME as following

c://Programfiles/Java/jdk-1.6/bin // with and without bin , with and without double slash

no result


I also tried

;c://Programfiles/Java/jdk-1.6/bin // with and without bin , with and without double slash

no result


Are there any other possible solutions

PS The System varialbes box is disabled . so i can only add user variables

Donotello
  • 157
  • 2
  • 2
  • 14

4 Answers4

2

Several problems with your approach:

  1. The environment variable JAVA_HOME has nothing to do with the mechanism that your operating system uses for finding executable files. For this the PATH variable is considered. The JAVA_HOME variable is sometimes used by other applications looking for Java.

  2. If using the variable JAVA_HOME, it should be set to the parent directory of the bin directory.

  3. Windows uses back slashes for separating directories, not forward slashes. (EDIT: At least, Windows 7 allows forward slashes, but I would suggest to still use back slashes.) Additionally, there is only one separator between "C:" and the the root directory.

  4. The directory that usually contains installed programs is "Program Files", not "ProgramFiles"

Putting it all together you should do the following:

  1. Create the environment variable JAVA_HOME with your Java installation directory as value, e.g. "C:\Program Files\Java\jdk-1.6". This directory must contain the bin directory, which in turn contains the executable files (such as java.exe).

  2. Extend the environment variable PATH by adding ";%JAVA_HOME%\bin" at the end of it.

Both edits should be made in system variables. Now you simply can open a command prompt and check this setup with a "java -version". This should work.


EDIT

If only user variables can be edited in the environment settings, the following will work:

  1. Add a variable JAVA_HOME to the user variables, as mentioned above.
  2. Add a (new) variable PATH to the user variables with the content "%PATH%;%JAVA_HOME%\bin".

If you now open a command prompt and check the path variable by simply typing "path", you will see that the variables in the path are properly expanded. Now check with "java -version".

Seelenvirtuose
  • 20,273
  • 6
  • 37
  • 66
  • I'd was just about to +1 when I saw this: *Windows uses back slashes for separating directories, not forward slashes.* The first half is true, the second half not. – Ingo Feb 24 '14 at 15:21
  • Can you tell me, where Windows (I speak of Windows, not Java, as the question refers to the command prompt) is using forward slashes? – Seelenvirtuose Feb 24 '14 at 15:22
  • Windows 7 at least allows to use forward slashes (just verified that); I too have been tricked by the fact that Microsoft does indeed improve stuff in newer versions. Historically it was not possible to use them. – Gimby Feb 24 '14 at 15:25
  • I never checked that. And I also think, it's still better to use back slashes. But of course, I must edit my answer. Thanks. – Seelenvirtuose Feb 24 '14 at 15:27
  • Really! Color me stupid then, I could have sworn I couldn't do it in Windows 2000. – Gimby Feb 24 '14 at 15:42
  • @Ingo: Good findings, by the way. I never checked it out. I really should switch ... – Seelenvirtuose Feb 24 '14 at 15:45
2

By default, in order to be found by the shell, all programs have to be inside the system "path" environment variable, which is in no way related to the JAVA_HOME.

If you want configure both of them in the same time you can use the following:

set JAVA_HOME=jdk_path
set PATH=%JAVA_HOME%/bin;%PATH%
robermann
  • 1,722
  • 10
  • 19
1

Two step process:

  1. set JAVA_HOME=jdk_path;jdk_path\bin and
  2. set PATH=%JAVA_HOME%

Then, to confirm, run:

java -version

Matt
  • 477
  • 1
  • 5
  • 19
  • java home should not point to the bin directory. It should point to the java directory, one level up from bin. – Software Engineer Feb 24 '14 at 15:22
  • Replacing the entire PATH with only JAVA_HOME is also not really a good suggestion; that just creates other problems probably. – Gimby Feb 24 '14 at 15:26
  • if this is done in a single session/cmd prompt, it will ONLY impact that session. obviously (or perhaps it isn't obvious) your path would also contain whatever else you need. But the java path has to be on the PATH in order for it to work correctly. I found that setting JAVA_HOME to both bin and path to get java and javac commands to work is necessary, and you can toggle versions of java if you have older code (compiled under different versions) more easily by setting JAVA_HOME then. – Matt Feb 24 '14 at 15:37
1

What commands are or are not recognized at the command prompt has nothing to do with the JAVA_HOME environment variable, but with the PATH variable.

You can check your path in windows command line with

C:\>  path

Apart from that, be sure to point to the correct jdk1.7 bin directory. It is a bad idea to call this ...Java/jdk-1.6/bin

Ingo
  • 36,037
  • 5
  • 53
  • 100