javac的:将警告视为错误 [英] Javac: Treat warnings as errors

查看:139
本文介绍了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.

我发现它通过此博客条目​​以及我自己的测试code(在NetBeans使用Ant)。输出是:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆