无法阻止 ant 生成编译器 Sun 专有 API 警告

2022-09-04 07:41:16

我从我的蚂蚁脚本中调用javac,如下所示:

<javac srcdir="src" 
   destdir="build/classes" source="1.6" 
   target="1.6" debug="true" encoding="Cp1252"
   nowarn="true"> 

但它仍然在输出中抛出编译器警告:

[javac] Compiling 73 source files to C:\IKOfficeRoot\Java\ERP\Framework\build\classes

[javac] C:\IKOfficeRoot\Java\ERP\Framework\src\de\ikoffice\util\LoggerFactory.java:49: warning: sun.reflect.Reflection is Sun proprietary API and may be removed in a future release
[javac]         return Logger.getLogger(Reflection.getCallerClass(2));
[javac]                                 ^
[javac] Note: C:\IKOfficeRoot\Java\ERP\Framework\src\de\ikoffice\db\SingleShotResultSet.java uses or overrides a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 1 warning

我也试过

<compilerarg line="-Xlint:-unchecked -Xlint:-deprecation"/>

<compilerarg value="-Xlint:none"/>

但这也没有效果。如何删除警告?


答案 1

将选项添加到命令行对我有用。-XDignore.symbol.filejavac


答案 2

执行此操作的最佳方法是使用抑制,即用于整个编译,或在所需的范围内。sunapi-Xlint:-sunapi@SuppressWarnings("sunapi")

请注意,使用此抑制的唯一方法是首先使用编译器选项启用它-XDenableSunApiLintControl

enableSunApiLintControl


推荐