aspose file tools*
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread "main" java.lang.NoClassDefFoundErorr: com/sun/tools/javac/Main" Watch "Exception in thread "main" java.lang.NoClassDefFoundErorr: com/sun/tools/javac/Main" New topic
Author

Exception in thread "main" java.lang.NoClassDefFoundErorr: com/sun/tools/javac/Main

Christopher Howerter
Greenhorn

Joined: Jan 09, 2010
Posts: 3
I have done everything I can to stop this error, as there were some issues with Windows Vista 32-bit DEP, so I disabled it for EVERY .exe file in the JDK folder and the folder where I store my programs (e.g. java.exe, javac.exe, etc.) The error occurs in the command prompt when I'm in the folder where my programs are. I also tried running the command promprt both normally and as an Administrator.

I type the following (as a test, since this remedial file exists):

javac Helloworld.java

I do this in order to create the .class file, but that doesn't happen and instead I get that error. It's now 3:30 a.m. and I've given up...Lord knows there is a "stupid" mistake of somesort or just Windows being stupid (I hope it's the latter!), but please help if you can!

Thanks,
Chris
Bupjae Lee
Ranch Hand

Joined: May 14, 2007
Posts: 107
It seems that JDK doesn't installed properly. Try reinstalling JDK.
Andre Brito
Ranch Hand

Joined: Dec 13, 2007
Posts: 95

Create a Test.java, with a main printing "test" in the C: (or home, if you're a linux user). Go there and type javac Test.java. If compiled, it's probably some error in your packages. If didn't compile, check if CLASSPATH, Path and JAVA_HOME are configured properly (test this using a 'javac' command in the console, without the java class - if the parameters are presented, it's ok. If not, you must configure your environment variables).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39851
    
  28
Disagree. Don't set a CLASSPATH at all.

What error message do you get when you write "javac HelloWorld.java"? Look at the Java™ Tutorials"problems" link.
Christopher Howerter
Greenhorn

Joined: Jan 09, 2010
Posts: 3
Well unfortunately another set of errors seem to have crept up...

They appear in this order when typing: javac Helloworld.java

Registry key 'Software\JavaSoft\Java Runtime Environment\CurrentVersion' has value '1.6', but '1.3' is required.
Error: could not find java.dll
Error: could not find Java 2 Runtime Environment

Any clues? I don't want to go messing around with the registry, but downgrading the version (let alone the fact that it is requiring it) just doesn't seem to make any sense!

FYI, I recently updated everything: 'JDK 6 Update 10' and 'JRE 6 Update 17' and installed 'JavaFX Production Suite 1.2' and 'Java EE SDK 5.08 (w/GlassFish v2.1.1)' and 'NetBeans IDE 6.8 for Java'--those caused these somewhat new errors--see below.

Don't ask why I installed all of that stuff, other than to be up-to-date. I must mention that the .java files for which I'm trying to create .class files with javac.exe were created and run years ago (c. 2005) when I took a Java programming course at my university--the most current version was JDK 1.3.1 at the time, I believe (or at least it was pretty current). Nevertheless, the java.exe and javac.exe et al are from that JDK 1.3.1 CD disk that came with the text book (all sadly missing, though there are resources online).

Anyway, I stored all of the files I had in order to run the .java files unto a floppy disk back in 2005 (that's the media we used to store them and run them in the computer labs and at home). So, due to my wanting to get back into programming, I went and found a computer with a 3.5 floppy drive and emailed all of the .java files that I created (along with the .exe files) to myself in order to download them on my laptop (no .class files existed strangely enough, even though my applets were there). Nevertheless, it's also important to note that before I installed all of the new, aforementioned software, I was still getting the aforementioned, three errors (due to the JDK 6 Update 10 being installed, which was preexisting on my computer before I ever had the idea to start programming again). So, I uninstalled it and then reinstalled the JDK 1.3.1 and that solved the above three errors, as version 1.3 was restored to the registry and the .dll must have shown up somewhere and an earlier Runtime Environment must have been restored. More importantly, it was then that I got the 'Exception in thread "main" java.lang.NoClassDefFoundErorr: com/sun/tools/javac/Main' error--the reason I started this thread to begin with.

So, the problem seems to be at least two-fold and also seems to have a number of angles to it. Thank you greatly to anyone who can help--"may the force be with you!"
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Ok, the answer is pretty simple, I think: your old Java install is being found on your path; perhaps the new one is not on the patha at all. Use your system control panel to add the "bin" directory of the new install at the beginning of your path, and find and delete your jdk1.3.1.


[Jess in Action][AskingGoodQuestions]
Christopher Howerter
Greenhorn

Joined: Jan 09, 2010
Posts: 3
Ok, well this simple information was indeed helpful, for things are starting to make sense. However, I have Windows Vista x86 and I'm thinking this is an "idiosyncraticy" thereof.

I set the class path--set CLASSPATH=C:\program files\java\jdk1.6.0_10\bin, and after moving Helloworld.java to that directory (having had to approve it through Vista's stupid WAC crap), I was actually able to create a .class file of Helloworld. To my surprise, however, it was not placed in that directory folder--it was placed in C:\users\christopher howerter\appdata\virtualstore\java\jdk1.6.0_10\bin!!!

I am pretty sure that this written to an alternate directory is due to the WAC, but I'm not sure (even running the command prompt "as an Administrator" does not rectify this issue)...I believe there is a stigma with writing a file to any directory within the program files directory (or Windows, etc.).

Nevertheless, I tried setting the CLASSPATH to that (what is a "hidden") directory--C:\users\christopher howerter\appdata\virtualstore\java\jdk1.6.0_10\bin, and it set just fine (as would anything, of course). So, I tried typing--java Helloworld--while in the C:\program files\java\jdk1.6.0_10\bin directory) and received a slew of errors, as it won't actually let me access this hidden directory in which the .class file exists through the command prompt (as it "does not exist," see above).

Then, I tried resetting the CLASSPATH to C:\program files\java\jdk1.6.0_10\bin, and just moved the created .class file from the hidden directory to that one (where the .java file exists, of course, as I moved it there--see above). I tried yet again running it and got the same list of errors:

Exception in thread "main" java.lang.NoClassDefFoundErorr: Helloworld
Caused by: java.lang.ClassNotFoundException: Helloworld
at java.net.URLCLassLoader$1.run<URLClassLoader.java:200>
at java.security.AccessController.doPriviledged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: Helloworld. Program will exit.

All I can say is that I hope all of that error code typing was not in vain (since one can't copy from the command prompt, at least to the best of my knowledge, which isn't very great...)! I was never taught how to diagnose these sorts of errors--only to double and triple check the code! However, who could screw up Helloworld?--rhetorical question, I assure you.

BTW, after trying to help me some more, as a side question, where can you find resources to try and solve huge strings of errors like that? I know they can often be caused by one typo and fixed at the snap of a finger, but for something like this.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.lang.NoClassDefFoundErorr: com/sun/tools/javac/Main