Java Forum / First Aid / November 2005
cant's compile with javac
Ido.Yehieli@gmail.com - 27 Nov 2005 21:37 GMT Hi, whenever I try to compile something with javac from the command prompt (windows XP) i get the following error: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
even if I just write "javac" without a file to compile i get the same error. The only time when i works correctly is when I'm in the bin directory that contains javac, the i can compile everything. If i change to a different directory it doesn't work and i get the afordmentioned error. one more thing - when i compile from eclipse it works, i only get it when manually compiling for the command prompt. I'm using version 1.5 update 5 (the last one) but it happened with earlier versions as well (1.5 update 1, update 2, etc..)
Thanks in advance for your help.
Ido.Yehieli@gmail.com - 27 Nov 2005 21:42 GMT I forgut to mention, I've added the bin directory to my PATH. I've added: C:\Program Files\Java\jdk1.5.0_05\bin; to it, and that is where it is really located.
Noodles Jefferson - 27 Nov 2005 21:47 GMT In article <1133127445.931575.32890@g43g2000cwa.googlegroups.com>, Ido.Yehieli@gmail.com took the hamburger, threw it on the grill, and I said "Oh wow"...
> Hi, whenever I try to compile something with javac from the command > prompt (windows XP) i get the following error: [quoted text clipped - 12 lines] > > Thanks in advance for your help. cd go/to/the/directory/where/your/javafile/is then javac Yourfile.java
 Signature Noodles Jefferson mhm31x9 Smeeter#29 WSD#30 sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
"Our earth is degenerate in these latter days, bribery and corruption are common, children no longer obey their parents and the end of the world is evidently approaching." --Assyrian clay tablet 2800 B.C.
Ido.Yehieli@gmail.com - 27 Nov 2005 22:11 GMT it just says: Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
when I dod that.
Noodles Jefferson - 28 Nov 2005 01:40 GMT In article <1133129500.547883.85290@o13g2000cwo.googlegroups.com>, Ido.Yehieli@gmail.com took the hamburger, threw it on the grill, and I said "Oh wow"...
> it just says: > Exception in thread "main" java.lang.NoClassDefFoundError: > com/sun/tools/javac/Main > > when I dod that. NoClassDefFoundError means that whatever you're looking to compile can't be found by the compiler. You can compile something by being in the same directory as where your source file is or you can use a path with javac which tells it to look for your source file, then compile it.
(I think there's more ways than just that to compile but I'll leave that to the hotshots of the group to expound on.)
Compile from the same directory as your source:
open a command prompt.
c:\stuff\morestuff> -- where you're at right now. I'm sure you know this already.
K: -- navigate to the K: drive (I usually do this from the top directory on the drive; for example, C:> but others may do that differently) cd.. -- move up one folder cd directoryName -- move to the directory (which would be directoryName) dir -- show everything in the folder you're in cd directoryName\anotherDirectory -- Move to the directoryName folder then go anotherDirectory within that.
Once you're there, javac YourFile.java
javac using a path:
javac just\tell\thecompiler\where\it\can\find\your\file\YourFile.java
If the file's on another drive, I'll navigate to the drive and then start my path. That's just what I do though. Others may have a different/better way.
If Eclipse can find it, you can find it because it can't compile stuff out of thin air. It has to find a source somewhere.
 Signature Noodles Jefferson mhm31x9 Smeeter#29 WSD#30 sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
"Our earth is degenerate in these latter days, bribery and corruption are common, children no longer obey their parents and the end of the world is evidently approaching." --Assyrian clay tablet 2800 B.C.
Roedy Green - 28 Nov 2005 03:20 GMT On Sun, 27 Nov 2005 19:40:06 -0600, Noodles Jefferson <silverbells@tacoshells.com> wrote, quoted or indirectly quoted someone who said :
>NoClassDefFoundError means that whatever you're looking to compile can't >be found by the compiler. that's a run time error. It means Javac can't find part of itself.
Uninstall all java and reinstall as per http://mindprod.com/jgloss/jdk.html
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Ido.Yehieli@gmail.com - 27 Nov 2005 22:13 GMT BTW when i compile with eclipse and then run "java nameOfTheClassIWasCompiling" it works fine, just "javac nameOfTheClassIWasCompiling.java" doesn't work
Noodles Jefferson - 28 Nov 2005 01:13 GMT In article <1133129586.492674.187080@g47g2000cwa.googlegroups.com>, Ido.Yehieli@gmail.com took the hamburger, threw it on the grill, and I said "Oh wow"...
> BTW when i compile with eclipse and then run "java > nameOfTheClassIWasCompiling" it works fine, just "javac > nameOfTheClassIWasCompiling.java" doesn't work I can't answer that one, I don't know anything about Eclipse. Yet.
 Signature Noodles Jefferson mhm31x9 Smeeter#29 WSD#30 sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
"Our earth is degenerate in these latter days, bribery and corruption are common, children no longer obey their parents and the end of the world is evidently approaching." --Assyrian clay tablet 2800 B.C.
Ido.Yehieli@gmail.com - 28 Nov 2005 01:24 GMT OK, bit the question is not why it is compilng with eclipse, but rather isn't it compiling when using javac outside of JAVA_HOME\bin? I mean, if it was a PATH problem, then why is "java" working? and if it was a problem with "javac" then why is it working in JAVA_HOME\bin directory but not in any other directory?
Noodles Jefferson - 28 Nov 2005 02:22 GMT In article <1133141057.346011.321100@f14g2000cwb.googlegroups.com>, Ido.Yehieli@gmail.com took the hamburger, threw it on the grill, and I said "Oh wow"...
> OK, bit the question is not why it is compilng with eclipse, but rather > isn't it compiling when using javac outside of JAVA_HOME\bin? > I mean, if it was a PATH problem, then why is "java" working? > and if it was a problem with "javac" then why is it working in > JAVA_HOME\bin directory but not in any other directory? Your JAVA_HOME variable's set wrong. Lose the \bin.
 Signature Noodles Jefferson mhm31x9 Smeeter#29 WSD#30 sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
"Our earth is degenerate in these latter days, bribery and corruption are common, children no longer obey their parents and the end of the world is evidently approaching." --Assyrian clay tablet 2800 B.C.
Rhino - 28 Nov 2005 05:19 GMT > OK, bit the question is not why it is compilng with eclipse, but rather > isn't it compiling when using javac outside of JAVA_HOME\bin? > I mean, if it was a PATH problem, then why is "java" working? > and if it was a problem with "javac" then why is it working in > JAVA_HOME\bin directory but not in any other directory? I think you may be confusing PATH with CLASSPATH. PATH identifies where your key Java executables - particularly java and javac - are situated. CLASSPATH identifies where your .class files (executable versions of your source code) are situated. PATH and CLASSPATH are frequently quite different. It sounds like you have PATH set fine but I think you need to look into CLASSPATH: find out what it does and how to set it to what you want.
Eclipse handles your CLASSPATH for you by letting you add additional class files and/or jars so that they can be 'seen' by the Eclipse execution modules. When you use the command line, you have to set the CLASSPATH yourself.
Rhino
Ido.Yehieli@gmail.com - 28 Nov 2005 11:37 GMT ok now I've set my CLASSPATH, but it didn't help much... this comes directly from my console:
here it works:
>-----begin screen shot-----< D:\Program Files\Java\jdk1.5.0_05\bin>javac Usage: javac <options> <source files> where possible options include: -g Generate all debugging info -g:none Generate no debugging info -g:{lines,vars,source} Generate only some debugging info -nowarn Generate no warnings -verbose Output messages about what the compiler is doing -deprecation Output source locations where deprecated APIs are used -classpath <path> Specify where to find user class files -cp <path> Specify where to find user class files -sourcepath <path> Specify where to find input source files -bootclasspath <path> Override location of bootstrap class files -extdirs <dirs> Override location of installed extensions -endorseddirs <dirs> Override location of endorsed standards path -d <directory> Specify where to place generated class files -encoding <encoding> Specify character encoding used by source files -source <release> Provide source compatibility with specified release -target <release> Generate class files for specific VM version -version Version information -help Print a synopsis of standard options -X Print a synopsis of nonstandard options -J<flag> Pass <flag> directly to the runtime system
>-----end screen shot-----< now, when i move away from the directory that contains javac it doesn't work:
>-----begin screen shot-----< D:\Program Files\Java\jdk1.5.0_05\bin>cd ..
D:\Program Files\Java\jdk1.5.0_05>javac Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
D:\Program Files\Java\jdk1.5.0_05>cd d:\java\server
D:\java\server>dir Volume in drive D is data Volume Serial Number is 789B-E0A5
Directory of D:\java\server
23/11/2005 15:38 <DIR> . 23/11/2005 15:38 <DIR> .. 10/12/2004 11:35 142 NetPrinter.java 10/12/2004 11:35 1,016 Server.java 2 File(s) 1,158 bytes 2 Dir(s) 909,910,016 bytes free
D:\java\server>javac Server.java Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
D:\java\server>javac -classpath . Server.java Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
D:\java\server>echo %CLASSPATH% "d:\Program Files\Java\jdk1.5.0_05\bin";.
>-----end screen shot-----< was also that way when CLASSPATH was just . (period).
thanks, Ido,
Bjorn Abelli - 28 Nov 2005 12:11 GMT > D:\java\server>echo %CLASSPATH% > "d:\Program Files\Java\jdk1.5.0_05\bin";. If the CLASSPATH environment variable points to just that directory, it doesn't do you any good anyway, as there are no classes in that directory, or at least it shouldn't be...
> was also that way when CLASSPATH was just . (period). AFAIK Sun has recommended since jdk 1.2 to *not* set the CLASSPATH environment variable at all, unless special circumstances demands it.
See what happens if you drop the CLASSPATH environment variable altogether.
Another question is where you have put the libraries.
Is the tools.jar in "d:\Program Files\Java\jdk1.5.0_05\lib" where it should be?
// Bjorn A
Ido.Yehieli@gmail.com - 28 Nov 2005 13:27 GMT > See what happens if you drop the CLASSPATH environment variable altogether. I've only added the classpath cariable after someone here told me to! it happened before that as well. And it happens when i remove classpath altogether.
> Another question is where you have put the libraries. > > Is the tools.jar in "d:\Program Files\Java\jdk1.5.0_05\lib" where it should > be? I havn't moved anything myself, it is exactly where sun's installer have put them. I'll take another look when i return home to my computer, but I'm quite sure that isn't the problem
Ido.Yehieli@gmail.com - 28 Nov 2005 14:53 GMT yes, tools.jar is in D:\Program Files\Java\jdk1.5.0_05\lib
Ido.Yehieli@gmail.com - 28 Nov 2005 15:19 GMT There is one more thing: I tried temporarily renameing the directories jdk1.5.0_05 and jre1.5.0_05 and it seems "java" comes from jre1.5.0_0 not from jdk1.5.0_05. but my PATH include jdk1.5.0_05 not jre1.5.0_05! how is this possible?
Roedy Green - 28 Nov 2005 16:00 GMT >I tried temporarily renameing the directories jdk1.5.0_05 and >jre1.5.0_05 and it seems "java" comes from jre1.5.0_0 not from >jdk1.5.0_05. but my PATH include jdk1.5.0_05 not jre1.5.0_05! how is >this possible? There is a copy of java.exe in the windows directory that uses the registry to find the real java.exe.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Roedy Green - 28 Nov 2005 15:59 GMT >D:\Program Files\Java\jdk1.5.0_05\bin>cd .. > >D:\Program Files\Java\jdk1.5.0_05>javac You should have only one javac.exe on your Windows machine. Use "find" to see how many you have.
See http://mindprod.com/jgloss/registry.html to see what the Java entries in the registry should look like.
Unfortunately my site is still down. There must have been some trouble with the move.
The fastest way to get your system up and going it to uninstall all JREs and JDKs, and remove any remaining files. Prune the Java stuff out of the registry and start again installing the JDK 1.5.0_05.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Ido.Yehieli@gmail.com - 28 Nov 2005 16:41 GMT > You should have only one javac.exe on your Windows machine. Use "find" > to see how many you have. That's it! i have all the java executables in C:\WINDOWS\system32. how did it get there? should i just delete them all? I'll take a look at your web site aswell, when it's online again.
Thanks, Ido.
Ido.Yehieli@gmail.com - 28 Nov 2005 16:44 GMT Ok, deleting them solvet it. Thanks a lot to everyone who've helped! if only the lisp community would be that newb-friendly....
Roedy Green - 28 Nov 2005 03:19 GMT >even if I just write "javac" without a file to compile i get the same >error. see http://mindprod.com/jgloss/gettingstarted.html http://mindprod.com/jgloss/helloworld.html
server is down for upgrade.
 Signature Canadian Mind Products, Roedy Green. http://mindprod.com Java custom programming, consulting and coaching.
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|