这适用于我在 Windows 8.1 x64 和 Java 1.8.0_05 下的 Netbeans 8.0。我只能假设它最近已修复。
Messager cm = processingEnv.getMessager();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
System.getProperties().storeToXML(baos, "System Properties");
}
catch (IOException ex) {
cm.printMessage(Kind.ERROR, "Exception while getting System properties as XML: " + ex.getMessage());
}
cm.printMessage(Kind.NOTE, "\System.properties XML:\n" + baos.toString());
这会给我
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>System Properties</comment>
<entry key="java.runtime.name">Java(TM) SE Runtime Environment</entry>
<entry key="java.vm.vendor">Sun Microsystems Inc.</entry>
...
</properties>
jbunting 的anwser(即使用 processingEnv.getOptions())对于将键值对干净地传递给注释处理器肯定更正确。