0

OK, what am I doing wrong, this is driving me nuts.

I am trying to install the latest JDK (1.6.0_23). So, I downloaded it from Oracle's awful site and then ran the installation. I installed it to C:\Java\jdk1.6.0_23

Then, I created a JAVA_HOME User Variable that pointed to C:\Java\jdk1.6.0_23. I then added a piece to the end of my Path environment variable that says %JAVA_HOME%\bin.

However, when I try to simply open a command prompt and run simple java commands, I am told it is not a recognizable command. I have to manually cd into the that bin directory to do anything.

Do I also need a Classpath variable that points to the JRE? I noticed there was a Classpath variable there previously that pointed to jre/lib/QTJava.zip, but I deleted it.

If you have the JDK installed and a JAVA_HOME variable setup, do I still need the JRE in the classpath? I am running Windows 7 and do all of my development in Eclipse.

3
  • Show us exactly what the environment variable is set to. Your description is ambiguous. Commented Dec 11, 2010 at 3:54
  • JAVA_HOME=C:\Java\jdk1.6.0_23 this is the user variable Commented Dec 11, 2010 at 3:55
  • Path=C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\android-sdk_r05-windows\android-sdk-windows\tools;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Windows Live\Shared;%JAVA_HOME%\bin;%M2% Commented Dec 11, 2010 at 3:56

3 Answers 3

1

Maybe the problem is because you set JAVA_HOME as a user variable, but trying to reference it from the PATH which is a system variable (or is it?). You cannot do this, because system variables are evaluated before user variables.

There are two possible solutions: 1. Set JAVA_HOME as a system variable instead 2. Create a new user variable PATH and set %JAVA_HOME%\bin there. The user PATH and the system PATH variables will be concatenated at runtime automatically.

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

2 Comments

Adding to this, an obvious suggestion I haven't seen mentioned explicitly is to type echo %PATH% in cmd. Everything should be expanded. My guess is that the variable %JAVA_HOME% did not resolve properly. Also note that if you use set in cmd, my experience is that this does not persist across multiple instances of cmd, so instead you should do the Control Panel option (or right-click (My) Computer, etc.). There you can set %JAVA_HOME% so that it is on the same level as %PATH%. Also one more obvious suggestion: After making changes, try closing your cmd and opening a new one.
Yeah, I had to set JAVA_HOME as a system variable instead of user variable. Then, I could use %JAVA_HOME% references. Defining it in User vars then trying to use it in Environment variables does not work as rodion said above. Thanks everyone.
1

From http://social.answers.microsoft.com/Forums/en-US/vistainstall/thread/48b23109-9fbc-47c5-a5d1-465773f94704

(at the end)

1) Enable 'delayed variable expansion' in the registry (see http://batcheero.blogspot.com/2007/06/how-to-enabledelayedexpansion.html)

2) Change the '%' signs around var2 to '!', e.g. "%var2%" becomes "!var2!"

I've done some limited testing on Windows 7 and this appears to fix the problem.

Maybe try that, see if it fixes it (I don't have windows here to try)

Comments

1

Do I also need a CLASSPATH variable that points to the JRE?

Strictly speaking, no. The CLASSPATH variable may be used if you try to run a java class and you don't use the -cp or -jar options.

The CLASSPATH variable doesn't need to point to the JRE. The java.exe command etc all know where to find the JRE's runtime classes. (And they don't look on the CLASSPATH for them anyway.)

For the PATH problem, try running:

C:\Java\jdk1.6.0_23\bin\java.exe -version 

If that doesn't work then there's a problem with your actual installation. If it does work, try looking at what JAVA_HOME and PATH are set to in the environment variables of the command shell.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.