2

This problem is a bit embarrassing, and the solution is most likely on your web site somewhere, but I haven't been able to find it, so here goes: I've just installed Java to my C:\ drive, and while the machine can find java it can't find javac, to wit:

C:\>java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)


C:\>javac -version
Error: Could not find or load main class com.sun.tools.javac.Main

and I get the above response even when I'm sitting IN the bin directory. I'm stumped.

I've tried updating both the PATH and JAVA_HOME environment variables, and I'm sorta stuck. Can anyone help? Note: I'm glad to go to the appropriate spot on your site, but I haven't been able to locate it, if you just point me to it I will consider myself helped, and thanks.

McDowell
  • 107,573
  • 31
  • 204
  • 267
  • Tried re-installing jdk? – Aniket Inge Jan 24 '13 at 16:35
  • http://www.sachinmore.com/2008/01/unable-to-load-default-compiler-class.html – scrappedcola Jan 24 '13 at 16:35
  • 1
    cd to your `JAVA_HOME` dir. cd into the `lib` dir within `JAVA_HOME`. Verify that you have `tools.jar` in the `$JAVA_HOME/lib` dir. Is it there? – Alderath Jan 24 '13 at 16:41
  • Good answer, Alderath, that seems to be my trouble. When I looked in the JAVA_HOME\lib directory there was NO tools.jar. So, I guess I'll just take Aniket's advice and reinstall the JDK. Thanks to everyone who helped solve this mystery. – Dave Alvarez Jan 25 '13 at 14:08

2 Answers2

1

The problem may be because you might have installed JRE, so you are able to use java command

javac command is used compiling java programs, hence its for development

And for development you need to install JDK

Have a look at this :

What is the difference between JDK and JRE?

Community
  • 1
  • 1
Abubakkar
  • 15,488
  • 8
  • 55
  • 83
  • Thanks for your answer. No, it's a JDK, in fact it is jdk-7u11-windows-x64, which is correct for this machine. Must be something else. – Dave Alvarez Jan 24 '13 at 19:29
1

You need to specify the environment variable i.e. path. If you are using Windows 7, then Right click on my computer -> change settings -> advanced -> environment variable -> change path to bin folder of java (C:\Program Files\Java\jdk1.7.0_03\bin), no need to earse the prev path in path variable. Just give ";" at end, paste the link of the JDK's bin folder, and type ";".

wegry
  • 7,046
  • 6
  • 39
  • 59
Rakesh Burbure
  • 1,045
  • 12
  • 27
  • Thanks for your answer as well. I think I did specify the correct environment variable, at least when I type echo %PATH% what get reported back is – Dave Alvarez Jan 24 '13 at 19:32