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!

Dhairya Vora
  • 1,281
  • 12
  • 35
Sapphire
  • 91
  • 1
  • 1
  • 2
  • 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 – Java Ka Baby Sep 15 '11 at 22:32
  • no there's no other jdk1.7.0 inside it. – Sapphire Sep 15 '11 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. – Jason Dean Sep 16 '11 at 01: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. – Alex K Sep 16 '11 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` –  Jan 05 '13 at 23:22

3 Answers3

25

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

Stephan
  • 41,764
  • 65
  • 238
  • 329
mihk3l
  • 575
  • 1
  • 6
  • 9
  • @Nilabja, have you looked into [this](https://javatutorial.net/set-java-home-windows-10) tutorial? Did you restart your system after altering the java_home variable? – mihk3l May 23 '17 at 06:42
  • yupp, worked on my other machines perfectly though, I may be missing some step @mihk3l – Nilabja May 23 '17 at 08:40
  • Believe me if you are reading this, it worked like a charm, -From Frustrated Coder. – Deepesh Rehi Oct 10 '19 at 07:00
4

Try setting it to

JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0\jre
Jason Dean
  • 9,585
  • 27
  • 36
  • 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? – Jason Dean Sep 16 '11 at 01:35
  • Ant is expecting a **JDK**, not a JRE, so this is not going to work. – Jesper Nov 09 '12 at 12:18
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 .

Csaba Tenkes
  • 124
  • 7