I have a professor who always insists on
"sitting in the root of the source tree when invokingjavac
(and in the root of the directory when invokingjava
)".
Although, for the basic programs I have done, I have never found the need of doing that.
So, what is the need of doing it?
It means that if you have a package, foo
, and a class or classes in that package:
package foo;
class Nifty {
// ...
}
...and your source tree looks like (and it mostly has to):
+ source + foo + Nifty.java
javac
will expect to be in the source
directory when you're compiling, not in the foo
directory. It's just how javac
is.
java
will expect that the classpath will include source
(not foo
), and like javac
work relative to that (looking in foo
for the classes in the package foo
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.