使 javac 将警告视为错误 [英] Make javac treat warnings as errors
本文介绍了使 javac 将警告视为错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 Ant 文件来编译我的程序.如果编译器报告了任何警告,我希望 javac 任务失败.关于如何做到这一点的任何线索?
解决方案
使用 -Werror
标志.它没有列在 -help
输出中,但它可以工作.
我是通过这篇博客文章找到的,并且在我自己的代码上测试(在 NetBeans 和 Ant 中).输出是:
<前>MyClass.java:38: 警告:[serial] 可序列化类 MyClass 没有对 serialVersionUID 的定义公共类 MyClass 扩展 JComponent {1 条警告构建失败(总时间:3 秒)请注意,这仅适用于 Java 6.
编辑:在 Ant 构建文件中指定此项的示例:
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath"><compilerarg value="-Xlint:all"/><compilerarg value="-Werror"/></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?
解决方案
Use the -Werror
flag. It's not listed in the -help
output, but it works.
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)
Note that this is Java 6 only, though.
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屋!
查看全文