尝试在PowerShell上运行Java文件时不存在软件包
我有一个名为PackageTest的Eclipse项目,其中有两个软件包,每个软件包都有一个。
这是两者的代码:
package test;
import apple.Apple;
public class Main {
public static void main(String[] args) {
Apple apple = new Apple(5);
}
}
package apple;
public class Apple {
private int value;
public Apple(int value) {
this.value = value;
}
}
我可以从eclipse内部运行main.java,但是当我尝试使用时:
java (rest of directory)\PackageTest\src\test\Main.java
在命令行上,我收到此错误:
import apple.Apple;
^
Main.java:6: error: cannot find symbol
Apple apple = new Apple(5);
^
symbol: class Apple
location: class Main
Main.java:6: error: cannot find symbol
Apple apple = new Apple(5);
^
symbol: class Apple
location: class Main
3 errors
error: compilation failed
是的,我尝试过
java (rest of directory)\PackageTest\src\test\Main.java --cp (rest of directory)\PackageTest
I have an eclipse project named PackageTest with two packages with one file inside each.: src/apple/Apple.java and src/test/Main.java.
Here is the code of both:
package test;
import apple.Apple;
public class Main {
public static void main(String[] args) {
Apple apple = new Apple(5);
}
}
package apple;
public class Apple {
private int value;
public Apple(int value) {
this.value = value;
}
}
I can run Main.java just fine from inside eclipse, but when I try to use:
java (rest of directory)\PackageTest\src\test\Main.java
On the command line, I receive this error:
import apple.Apple;
^
Main.java:6: error: cannot find symbol
Apple apple = new Apple(5);
^
symbol: class Apple
location: class Main
Main.java:6: error: cannot find symbol
Apple apple = new Apple(5);
^
symbol: class Apple
location: class Main
3 errors
error: compilation failed
And yes, I have tried
java (rest of directory)\PackageTest\src\test\Main.java --cp (rest of directory)\PackageTest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Java源代码软件包是一个大型层次命名空间。
尝试更改为Apple类的文件夹结构。该项目需要一个用于Java类的主/Java文件夹。
src/ main/java /apple/apple.java
示例:
问候。
The Java source code packages as one big hierarchical namespace.
Try change to folder structure for Apple Class. The project need a main/java folder for java class.
src/main/java/apple/Apple.java
Example:
Regards.