I am sure this topic has been covered before but I want to post something new because I have tried everything that I have seen on the web and I am still having problems. The history of my problem goes as follows:
I have Fedora 2 installed on my machine.
Logged in as root I installed j2sdk1.4.2_07 from java.sun.com. /usr/local/j2sdk1.4.2_07 is the install directory
copy the self-extracting bin file over, made it executable and ran it
The install went ok, however when i went to use /usr/local/j2sdk1.4.2_07/bin/javac it was not working. I kept getting "command not found." Even though I was attempting to run the actual file. I did not think environment varibles mattered.
I researched "activating javac" and found info on how to install the pluggin for netscape/mozilla. I was able to do that successfully but still javac was NOT working
I added /usr/local/j2sdk1.4.2_07 to my PATH and javac worked??? I don't understand why it did not work before.
I wrote a small hello world program and I am getting exeption in thread "main" java.lang.noClassDefFoundError. The program compiles okay but when I run it I get that error.
I attemped to set up the CLASSPATH to /usr/local/j2sdk1.4.2_07/lib/tools.jar:/usr/local/j2sdk1.4.2_07/jre/lib/rt.jar and JAVA_HOME to /usr/local/j2sdk1.4.2_07 and still I get the same error.
PATH, CLASSPATH and JAVA_HOME are set in the /etc/profile
As far as I know everything is set up properly. Please help!
this will probably end up moved to the Linux/Unix forum before too long, but...
could you do a "ls -l" on your /usr/local/j2sdk1.4.2_07/bin directory and copy&paste the results here, to see if "java" and "javac" are present and have the correct permissions? if you also cut&pasted your environment variables, that might help too. (that should be the "set" command in bash, but i'm not at a linux box ATM so i can't verify that.)
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then INPUTRC=/etc/inputrc fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME CLASSPATH
for i in /etc/profile.d/*.sh ; do if [ -r "$i" ]; then . $i fi done
(Marilyn cut long lines) [ February 01, 2005: Message edited by: Marilyn de Queiroz ]
Joined: Jan 14, 2005
the only thing i can see that's clearly wrong is that the CLASSPATH shouldn't have to be set. it definitely shouldn't include those two JARs. i'm not even sure if you need JAVA_HOME set, but perhaps you do.
edit: or do you mean the "java" binary won't run your own compiled java programs? if so, try setting CLASSPATH to either be just ".", or else to at least include "." as one of its directories. then cd to wherever you keep your class files and try to run them from there. [ February 01, 2005: Message edited by: M Beck ]
Joined: Feb 01, 2005
I tried NOT setting the classpath and I get the same error.
Originally posted by M Beck: you have a command-line problem. you shouldn't be saying "java Test.class", but simply "java Test"; the JVM will add on the ".class" for you.
yeah, that bit is really confusing. it had me tearing my hair out for fifteen minutes, myself, when i got started.
This happens because Java uses "." to separate packages in a package heirarchy. Typically packages correspond to directories in the file system, so the JVM often turns "." into "/" (or the appropriate directory system for your OS). You can see this in the "ClassNotFound" error message. Notice that it says that it can't find "Test/class".