Netbeans 中的默认 ant 设置将属性 build.compiler.emacs
设置为 true
。这是什么意思? ant 文档只是说
Enable emacs-compatible error messages.
我知道emacs是一个编辑器,虽然我没有使用过它。将此属性设置为 true 或 false 会产生什么效果?
最佳答案
您可能没有注意到 ant documentation 的那部分描述 javac 任务的内容在“Jikes Notes”中。这是一个在使用 jikes 时修改编译结果消息格式的设置。编译器的方式是,当 Emacs 编辑器调用 ant 时(例如,使用 JDEE environment 时),编辑器可以解析结果消息并跳转到与消息相关的文件中的正确位置。
NB 为一个非标准编译器提供这样的设置确实有点奇怪,而且似乎已经被放弃了近十年。
给定以下 ant build.xml
文件
<project name="mini" basedir="." default="compile">
<property name="build.compiler.emacs" value="off"/>
<property name="build.compiler" value="jikes"/><!-- invoke jikes instead of javac-->
<target name="compile">
<javac srcdir="." destdir="" classpath="." includeantruntime="false">
</javac>
</target>
</project>
编译一个存在语法错误的简单类会给出以下输出:
Buildfile: /Users/seb/projets/java/ant/build.xml
compile:
[javac] Compiling 1 source file to /Users/seb/projets/java/ant
[javac]
[javac] Found 1 semantic error compiling "Hello.java":
[javac]
[javac] 5. System.out.println("Hello, World!"+foo);
[javac] ^-^
[javac] *** Semantic Error: No accessible field named "foo" was found in type "Hello".
BUILD FAILED
/Users/seb/projets/java/ant/build.xml:5: Compile failed; see the compiler error output for details.
Total time: 1 second
当您通过将 build.compiler.emacs
属性更改为 on
获得此输出时:
Buildfile: /Users/seb/projets/java/ant/build.xml
compile:
[javac] Compiling 1 source file to /Users/seb/projets/java/ant
[javac] Hello.java:5:52:5:54: Semantic Error: No accessible field named "foo" was found in type "Hello".
BUILD FAILED
/Users/seb/projets/java/ant/build.xml:5: Compile failed; see the compiler error output for details.
Total time: 1 second
在后一个版本中,消息不那么花哨,Emacs 解析它们的能力更强。
关于Netbeans Ant build.compiler.emacs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24059886/