Forum Stats

  • 3,757,793 Users
  • 2,251,267 Discussions
  • 7,869,917 Comments

Discussions

Error: Could not find or load main class com.sun.tools.javac.Main

918595
918595 Member Posts: 6
Hi Everybody,

I'm using Windows 7 command prompt. I tried to do javac and I'm getting an error that says: Error: Could not find or load main class com.sun.tools.javac.Main.
I downloaded the JDK 7u3 and saved it to the following directory C:\users\joshuafinch\Java. Afterwards I set the PATH and CLASSPATH in the system environment variables.
The PATH was set to C:\users\joshuafinch\Java\jdk1.7.0_03\bin.
The CLASSPATH was set to C:\users\myusername\Java\jdk1.7.0_03\lib.

When I type the javac command in the following directory: C:\users\joshuafinch\Java\bin> I get the above error.
When I type java or java -version it indicates that it is working properly. It's just that when I type in javac or javac -version I get the error that was mentioned above. I'm using Notepad as a text editor. I saved the notebook file as a .java file and made sure I selected all files, plus, actually saved the file in the bin directory. I was trying to run a simple HelloWorld.java file. This problem is driving me crazy. I've been trouble shooting it off and on for the last 24 hours. Any help will be greatly appreciated.
Thanks. Josh
Tagged:
«1

Answers

  • gimbal2
    gimbal2 Member Posts: 11,949 Gold Trophy
    The CLASSPATH was set to C:\users\myusername\Java\jdk1.7.0_03\lib.
    And what broken document told you to do that? Remove the entire variable and try again.
    gimbal2
  • EJP
    EJP Member Posts: 32,920 Gold Crown
    The PATH was set to C:\users\joshuafinch\Java\jdk1.7.0_03\bin.
    Correct.
    The CLASSPATH was set to C:\users\myusername\Java\jdk1.7.0_03\lib.
    Incorrect. Don't set it at all, or at least remove this incorrect value.

    Not saying this will fix the problem, but it will fix something.
    EJP
  • 918595
    918595 Member Posts: 6
    edited Feb 20, 2012 5:02AM
    Thanks for the reply. I updated the paths. PATH to C:\users\joshuafinch\Java\jdk1.7.0_03\bin and CLASSPATH to C:\users\joshuafinch\Java\jdk1.7.0_03\lib.
    I even uninstalled the JDK and tried it again and it still isn't working properly. All of the YouTube videos make it look so easy. I can't imagine why javac would cause the following: Error: Could not find or load main class com.sun.tools.javac.Main.

    Edited by: 915592 on Feb 20, 2012 2:00 AM
  • EJP
    EJP Member Posts: 32,920 Gold Crown
    Thanks for the reply. I updated the paths ...
    CLASSPATH to C:\users\joshuafinch\Java\jdk1.7.0_03\lib.
    Still incorrect. "Don't set it at all, or at least remove this incorrect value".
  • gimbal2
    gimbal2 Member Posts: 11,949 Gold Trophy
    EJP wrote:
    Thanks for the reply. I updated the paths ...
    CLASSPATH to C:\users\joshuafinch\Java\jdk1.7.0_03\lib.
    Still incorrect. "Don't set it at all, or at least remove this incorrect value".
    And what broken document told you to do that? Remove the entire variable and try again.
    Its too bad that both our posts are not being read :/
    gimbal2
  • 918595
    918595 Member Posts: 6
    I deleted that classpath and left a period because it won't let you leave the path blank. Anyways, still no luck.
  • 918595
    918595 Member Posts: 6
    I uninstalled it again and then installed the earlier version which is the jdk1.6.0_025 version. For some reason my computer didn't like the jdk1.7.0_03 version. My guess is that if anyone else gets the "Error: Could not find or load main class com.sun.tools.javac.Main" while trying to do the javac command in Windows 7 command prompt then it has something to to with the new version. Perhaps, there is a bug in it or something?
  • 918595
    918595 Member Posts: 6
    Tried to use new jdk7. Uninstalled it and used the older version which was the jdk6. This cleared up the "Error: Could not find or load main class com.sun.tools.javac.Main."
  • 923758
    923758 Member Posts: 1
    I have exactly the same problem. Tried removing completely CLASSPATH,setting it to current directory (i.e. to "."), but still does not work. Btw, my OS is Windows XP. I´ll try with JDK6, too.
  • 918595
    918595 Member Posts: 6
    edited Mar 14, 2012 1:41PM
    Yes. It can be a real pain trying to get it to work. It took me an entire day to figure out how to get it to work on my computer. I never was able to solve my path problems. None of the Google information worked for me. However, I did find a shortcut solution. The only downside is it sucks having to write out the extension everytime. Anyways, after I got the JDK6 installed I was able to compile and run java programs with the following Windows command prompts (I'm using Windows 7 with a 64 bit system):

    C:\Program Files\Java\jdk1.6.0_25\bin>javac -classpath . HelloWorld.java
    C:\Program Files\Java\jdk1.6.0_25\bin>java -classpath . HelloWorld

    Note: you have to space the dot between -classpath and the program or it won't work. Follow the above javac and java examples precisely. Your path may be different if you saved it somewhere else and/or if the JDK is a different version.

    I was using Notepad. To get notepad to work right when you save files, you have to right click notepad and run as
    administrator. Also, you may have to go to Control Panel\User Accounts and Family Safety\User Accounts\Change User Account Control Settings, it's also under start menu at the top (click icon above the top of the user account name)Once you're here you need to turn off the control settings in order to get rid of (Access Denied errors).

    Plus, when you save your program in Notpad you need to put in .java in the extension and set the Save as Type to All Files. So it would look like this File-->Save As-->File Name: HelloWorld.java-->Save as Type: All Files.

    Lastly, you have to save the files in the bin which is the same place where you compile and execute the program. Otherwise it won't work.
    When you pull up the Windows command prompt it'll look like this: C:\users\your account name here
    Just cd.. then cd.. to C:\ then cd to program files then cd java then cd jdk1.6.0_25 then cd bin
    Once you're in the bin you can compile and run your program.
    Further, the JRE (Java Runtime Environment) automatically comes with the JDK6 (Java Development Kit 6) download.

    Anyways, some of this may be obvious and some of it may not. I wrote it down here just in case. Like I mentioned above it took me all day to acquire this info. By the time I figured it out I was extremely frustrated. There's nothing worse than needing to get an assignment done and not being able to get the software to work. I hope this helps.

    P.s. this is the program I ran using Notepad as a text editor:

    class HelloWorld{
    public static void main(String[] args){
    System.out.println("Hello, World!");
    }
    }

    Edited by: 915592 on Mar 14, 2012 10:33 AM

    Edited by: 915592 on Mar 14, 2012 10:36 AM

    Edited by: 915592 on Mar 14, 2012 10:40 AM
This discussion has been closed.