简体   繁体   English

仅使用javac坐在源代码树的根目录下? 这是什么意思?

[英]Use javac only sitting in the root of the source tree? What does it mean?

I have a professor who always insists on 我有一个教授总是坚持

"sitting in the root of the source tree when invoking javac (and in the root of the directory when invoking java )". “调用javac时坐在源树的根目录中(调用java时坐在目录的根目录中”)。

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: 这意味着如果您有一个包foo和该包中的一个或多个类:

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. javac应该位于source目录中,而不是foo目录中。 It's just how javac is. 这就是javac

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 ). java希望classpath包含source (不是foo ),并且像javac一样相对于source (在foo查找包foo的类)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM