This discussion is archived
1 2 Previous Next 18 Replies Latest reply: Aug 20, 2012 1:03 AM by 956648 RSS

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

918595 Newbie
Currently Being Moderated
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
  • 1. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    gimbal2 Guru
    Currently Being Moderated
    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.
  • 2. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    EJP Guru
    Currently Being Moderated
    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.
  • 3. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    918595 Newbie
    Currently Being Moderated
    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
  • 4. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    EJP Guru
    Currently Being Moderated
    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".
  • 5. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    gimbal2 Guru
    Currently Being Moderated
    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 :/
  • 6. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    918595 Newbie
    Currently Being Moderated
    I deleted that classpath and left a period because it won't let you leave the path blank. Anyways, still no luck.
  • 7. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    918595 Newbie
    Currently Being Moderated
    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?
  • 8. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    918595 Newbie
    Currently Being Moderated
    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."
  • 9. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    923758 Newbie
    Currently Being Moderated
    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.
  • 10. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    918595 Newbie
    Currently Being Moderated
    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
  • 11. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    DrClap Expert
    Currently Being Moderated
    915592 wrote:
    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).
    You wouldn't have had this problem if you had spent half a minute and created a folder of your own to store your Java stuff in. (If you can't figure out what to call it, let me suggest "C:\JavaStuff".) Windows doesn't want you to store your personal data under the "Program Files" directory, that's why it will only let administrators do that. So don't do that.
  • 12. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    924636 Newbie
    Currently Being Moderated
    I had the same problem. I tried all of the suggestions with the CLASSPATH environment variable but that didn't help. I tried all of the variations on the PATH variable, but again no go. This issue isn't with the CLASSPATH, it's with the installation.

    I ran across a website that referred to the javac.exe actually being a wrapper that fires com.sun.tools.javac.Main from the tools.jar in the JDK\lib. This got me thinking that the installation might have a problem with it because I couldn't find the tools.jar file. I originally downloaded the installation that only has Java7u3 in it, "jdk-7u3-windows-i586.exe". This was the cause of the issue. What I discovered is that if you download the Java SE 7u3 & Netbeans bundle, "jdk-7u3-nb-7_1_1-windows-ml.exe", that installation has all of the correct files in it.

    You still have to set the PATH variable correctly, and you should completely uninstall whatever old version of Java you have to ensure a clean install. As far as the CLASSPATH variable, I just deleted it entirely. Now my java installation is complete; I just successfully compiled and ran a simple "hello world" program!
  • 13. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    EJP Guru
    Currently Being Moderated
    This issue isn't with the CLASSPATH, it's with the installation.
    Correct.
    I originally downloaded the installation that only has Java7u3 in it, "jdk-7u3-windows-i586.exe". This was the cause of the issue.
    No it wasn't. The JDK contains javac.exe and tools.jar. The issue seems to have been with an incomplete installation of that.
    What I discovered is that if you download the Java SE 7u3 & Netbeans bundle, "jdk-7u3-nb-7_1_1-windows-ml.exe", that installation has all of the correct files in it.
    Sure it does, but so does the JDK download. You don't need to install Netbeans just to get the entire Java compiler.
    you should completely uninstall whatever old version of Java you have to ensure a clean install.
    That shouldn't be necessary. I have about five separate versions of the 1.6 JDK and JRE installed and I am able to use them all as Netbeans platforms, so they can certainly coexist.
  • 14. Re: Error: Could not find or load main class com.sun.tools.javac.Main
    956605 Newbie
    Currently Being Moderated
    Warning !!!

    Check your external libraries (such as .jar files) path were added to to your project. The path should have regular format. For example it supposed to not have special characters like as "+", ... or space.

    I had that serious problem before in Eclipse IDE, change the path directory of my project library and then everything is okay again.

    Hope your problem will be solved.
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points