9

I set my JAVA_HOME variable to point to the jdk and I added %JAVA_HOME%\bin to the Path variable. However, my ant script is not able to find the jdk. It's looking into the wrong folder for Java compiler. here's the error I'm getting.

com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to C:\Program Files\Java\jre6

I set my JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0

What am I doing wrong? Please help!

5
  • What other folders do you see in 'C:\Program Files (x86)\Java\jdk1.7.0' just make sure there is not another jdk1.7.0 folder inside this which gets created by unzip to option Commented Sep 15, 2011 at 22:32
  • no there's no other jdk1.7.0 inside it. Commented Sep 15, 2011 at 22:40
  • Is there a JRE folder? Also, are you intending to use the 32-bit JDK? The fact that it is in the Program Files (x86) folder indicates that it is the 32-bit version. Commented Sep 16, 2011 at 1:32
  • @Sapphire You can create command file for running you ant script. Before launching ant you can set PATH variable to guarantee correct java calling. Commented Sep 16, 2011 at 10:14
  • the message "It is currently set to C:\Program Files\Java\jre6" indicates you did not change JAVA_HOME properly. Open a commandline and verify it by running set java Commented Jan 5, 2013 at 23:22

3 Answers 3

29

If your Java installation directory has a space in its path name, you should use the shortened path name (e.g. C:\Progra~1\Java\jre6) in the environment variable instead.

  • Progra~1 = 'Program Files'
  • Progra~2 = 'Program Files(x86)'

Setting the JAVA_HOME Variable in Windows

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

3 Comments

@Nilabja, have you looked into this tutorial? Did you restart your system after altering the java_home variable?
yupp, worked on my other machines perfectly though, I may be missing some step @mihk3l
Believe me if you are reading this, it worked like a charm, -From Frustrated Coder.
4

Try setting it to

JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0\jre 

2 Comments

Where are you making this change? Are you doing it in the environment variables section of Advanced Setting in your computer properties? And are you restarting the program that you are trying to access it with? This includes CMD. In my experience programs will only look for a new environment variable when they launch. What happens when you type "ECHO %JAVA_HOME%" at the command line?
Ant is expecting a JDK, not a JRE, so this is not going to work.
0

When you want to use JAVA_HOME in your path variable it is recommended to use "%JAVA_HOME%\bin" instead of %JAVA_HOME%\bin .

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.