Could not find main class HelloWorld

后端 未结 10 1753
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 09:39

I installed Java 1.7.0 in the following folder C:\\Program Files\\Java. My operating system is Windows XP(Version 2002) with Service pack 3.

The envir

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 09:57

    Java is not finding where your compiled class file (HelloWorld.class) is. It uses the directories and JAR-files in the CLASSPATH environment variable for searching if no -cp or -classpath option is given when running java.exe.

    You don't need the rt.jar in the CLASSPATH, these was only needed for older versions of Java. You can leave it undefined and the current working directory will be used, or just add . (a single point), separated by ';', to the CLASSPATH variable to indicate the current directory:

    CLASSPATH: .;C:\...\some.jar

    Alternatively you can use the -cp or -classpath option:

    java -cp . HelloWorld
    

    And, as Andreas wrote, JAVA_HOME is not needed by Java, just for some third-party tools like ant (but should point to the correct location).

提交回复
热议问题