在命令行中使用包编译 Java 代码时出错? [英] getting error when I compile the Java code using package in commandline?
问题描述
我有这个目录结构:
project1/src/edu/course/firstweek/javacourse/Program1.java
上面一个包中的另一个文件:
Another file in one package above:
project1/src/edu/course/firstweek/program2.java
在program2.java的头文件中,我有
In the header of program2.java, I have
package edu.course.firstweek;
import edu.course.firstweek.javacourse.Program1;
现在到当我在命令行中运行以下命令时:
Now to when I run the following in commandline:
Javac src/edu/course/firstweek/program2.java,
我收到这个错误:
src/edu/course/firstweek/program2.java:14:error cannot find symbol
System.out.println(program1.print("hello world"));
symbol: variable Program1
location: class program2
2 errors
我可以看到编译器无法找到 program1
,但是我在 中有正确的
.我这里需要帮助,编译后,运行程序有什么需要考虑的.import
package
语句程序2
I can see that the compiler is not able to find the program1
,but I have the correct import
package
statement in program2
. I need help here and after compiling, is there something that needs to be taken into account for running the program.
谢谢
推荐答案
尝试进入里面的一个目录,即 cd src
然后编译Javac edu/course/firstweek/program2.java
Try going into one directory inside, i.e. cd src
and then compile Javac edu/course/firstweek/program2.java
为了运行,做java edu.course.firstweek.program2
这篇关于在命令行中使用包编译 Java 代码时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!