java - 尽管 .class 已经更新,为什么 javac 仍重新编译我的 .java?

标签 java javac recompile

我被告知 javac 足够聪明,它不会重新编译 .java,前提是这个 .java 有时间戳在 .class 之前。我只是发现它在我的机器上不起作用,我肯定在某个地方错了吗?

我的P.java位于.../eg/access下,其中P.java声明为access

eg 
 |- access 
      |- P.class
      |- P.java

然后,当我运行javac P.java时,每次都会重新编译,这是正常的还是我错了?

最佳答案

默认情况下,Javac 每次都会重新编译所有内容。您观察到的行为是正确的,并且是有意设计的。

看起来您可以为此行为指定一个选项:

-Xprefer:{newer,source}

Specify which file to read when both a source file and class file are found for a type. (See Searching For Types). If -Xprefer:newer is used, it reads the newer of the source or class file for a type (default). If the -Xprefer:source option is used, it reads source file. Use -Xprefer:source when you want to be sure that any annotation processors can access annotations declared with a retention policy of SOURCE.

取自:http://docs.oracle.com/javase/6/docs/technotes/tools/windows/javac.html

您可能还会想到 Eclipse 的编译器,我很确定它确实会进行增量编译 - 或者 ant 中的 javac 任务,它足够智能来找出此类情况。

关于java - 尽管 .class 已经更新,为什么 javac 仍重新编译我的 .java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8271282/

相关文章:

java - SIP 和 Java,从哪里开始?用什么开始?

cmd - java 命令有效但 javac 无效?

c# - 在 Rider 中重新编译 ASP.NET Core 应用程序而无需重复重新运行它

python - Pickle:处理更新的类定义

java - postman 如何将 ArrayList 中的 map 数据作为表单数据发布

java - isSearchable 什么时候会为 Oracle JDBC 列返回 false?

java - UltraESB 启动错误

javac junit 给出 "error: package org.junit does not exist"

ant - 在不同的jvm中运行ant任务