11

我有一个使用 jstl 和 Struts 1 标签的旧版 webapp。当我使用 Java 5/6 预编译 JSP 文件时,jstl 和 Struts 1 标记会抛出有关“未经检查或不安全的操作”的警告。例如,如果我使用以下标签:

<%@ page import="/anotherpage.inc" %>

引发以下警告:

[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.

如果我使用 -Xlint:unchecked 重新编译,我会得到有关有问题的 JSP 标记库的内部工作的详细信息。我想禁止所有未经检查的操作警告。我认为使用 -Xlint:-unchecked 会抑制警告,但事实并非如此。

在编译我的 JSP 页面时如何抑制这些警告?重新编码 JSP 标记库或更新一千个 JSP 页面是不切实际的。我正在寻找一个编译器标志来全局禁用警告,以便我可以看到除未经检查的警告之外的所有警告。谢谢!

4

3 回答 3

1

这些消息是(JDK >= 1.5 的强制性)注释,而不是警告。

compiler.note.unchecked.plural=\
    Some input files use unchecked or unsafe operations.

默认编译器行为与 with 相同-Xlint:-unchecked

随着-Xlint:unchecked您打开警告,报告每个实例。

compiler.warn.unchecked.assign=\
    [unchecked] unchecked assignment: {0} to {1}
...

强制注释不能单独禁用,它们都用 禁用-Xlint:none。不幸的是,其余的警告也被禁用了。

您可以检查其他响应以获取替代方案,但过滤编译器输出消息似乎是最简单的解决方案。

于 2011-04-26T10:21:04.857 回答
0

You are right that

-Xlint:unchecked

does the opposite of what you want, but you can also use

-Xlint:-unchecked

Note the extra "-" in there.

This will disable all warnings about unchecked operations, not just the ones generated by the tag library, but other warnings will still be shown.

于 2011-02-08T16:45:04.807 回答
0

禁用该警告的最佳方法是停止在 JSP 中使用 Java 代码。开始习惯于使用 JSTL 或 JSF(根据需要使用自定义标签库)。

但是对于遗留应用程序,您很可能无法做到这一点,您只需要忍受警告。当然,您可以将 -nowarn 标志添加到编译器,但这将禁用所有警告,而不仅仅是这个警告,这可能比您想要的更多。

于 2011-02-17T08:03:45.293 回答