我在java中有这些程序:
//file ../src/com/scjaexam/tutorial/GreetingsUniverse.java
package com.scjaexam.tutorial;
public class GreetingsUniverse {
public static void main(String[] args) {
System.out.println("Greetings, Universe!");
Earth e = new Earth();
}
}
//file ../src/com/scjaexam/tutorial/planets/Earth.java
package com.scjaexam.tutorial.planets;
public class Earth {
public Earth() {
System.out.println("Hello from Earth!");
}
}
我能够毫无错误地编译第二个使用:
javac -d classes src/com/scjaexam/tutorial/planets/Earth.java
这会将编译Earth.class
后的../classes/com/scjaexam/tutorial/planets/
文件按预期放入文件夹中。现在我必须编译主类GreetingsUniverse.java
,但是这个命令失败了:
javac -d classes -cp classes src/com/scjaexam/tutorial/GreetingsUniverse.java
src/com/scjaexam/tutorial/GreetingsUniverse.java:7: error: cannot find symbol
Earth e = new Earth();
^
symbol: class Earth
location: class GreetingsUniverse
src/com/scjaexam/tutorial/GreetingsUniverse.java:7: error: cannot find symbol
Earth e = new Earth();
^
symbol: class Earth
location: class GreetingsUniverse
编译(然后运行)这个程序的正确命令是什么?