A friend of mine wanted to start to learn java, and I wanted to help him, so we created a simple Hello World example.
public class Hello {
public static void main(String argv[]) {
system.out.println("Hello world !");
}
}
then, when you compile it:
> javac Hello.java
and want to execute it:
> java Hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello
We set the CLASSPATH and JAVA_HOME enviroment variable correctly, and the problem was still the same..
When we copied the Hello.class into a lib directory of JAVA_HOME, it worked, but not from the current directory !
We tried different versions of java.. and do you know where this stupid problem is?
in the CLASSPATH there should be:
CLASSPATH=.;c:/programme/jboss/lib;c:/programme/
j2sdk1.4.2_08/lib;c:/programme/j2sdk1.4.2_08/jre/lib; ...
yes.. a dot .. it means, that it will search for classes bytecode in the current directory !
you can also tell java to search the current directory with the -classpath parameter
> java -classpath . Hello
Problems like this can really discourage java newbies, and that moment was very embarassing :)
我的解決方法如下:java 設置環境變量 path c:/jkd6/bin classpath c:/jdk6/lib/dt.jar; c:/jdk6/lib/tools.jar
接下來在dos中輸入:
I've tried the command: set classpath=%classpath%;.; It works! Amazing Thanks.