Getting error “cannot find or load main class HelloWorld”

前端 未结 3 1244
鱼传尺愫
鱼传尺愫 2021-01-22 20:05

I have this simple code:

public class HelloWorld{
    public static void main(String[] args){
        System.out.println(\"HelloWorld\");
    }
}
3条回答
  •  再見小時候
    2021-01-22 20:24

    You could get this behaviour if you have an incorrect / inappropriate setting of the CLASSPATH environment variable; e.g. the current directory isn't on the classpath. (It is by default ... )

    Try this:

    java -classpath . HelloWorld
    

    Assuming that works ... the problem is your understanding of the concept of the "classpath". This is explained well by the Oracle documentation:

    • The java & javac command documentation ... particular the -classpath argument
    • Setting the Classpath.
    • The Java Tutorial - PATH and CLASSPATH

提交回复
热议问题