使javac将警告视为错误 [英] Make javac treat warnings as errors
本文介绍了使javac将警告视为错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Ant文件可以编译我的程序.如果编译器报告了任何警告,我希望javac任务失败.关于如何做到这一点的任何线索?
I have an Ant file that compiles my program. I want the javac task to fail if any warning was reported by the compiler. Any clue on how to do that?
推荐答案
使用-Werror
标志.它未在-help
输出中列出,但可以使用.
Use the -Werror
flag. It's not listed in the -help
output, but it works.
我通过此博客条目找到了它,并且在我自己的代码上进行了测试(在带有Ant的NetBeans中).输出为:
I found it through this blog entry and tested on my own code (in NetBeans with Ant). The output was:
MyClass.java:38: warning: [serial] serializable class MyClass has no definition of serialVersionUID
public class MyClass extends JComponent {
1 warning
BUILD FAILED (total time: 3 seconds)
但是请注意,这仅是Java 6.
Note that this is Java 6 only, though.
编辑:在Ant构建文件中指定此示例:
Edit: Example of specifying this in Ant buildfile:
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath">
<compilerarg value="-Xlint:all"/>
<compilerarg value="-Werror"/>
</javac>
这篇关于使javac将警告视为错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文