JDK 12 Javadoc Tag for System Properties
JDK 12 Early Access Build 20 (2018/11/15) is available and can be used to try out the new Javadoc tag {@systemProperty}
. The new {@systemProperty}
Javadoc tag is discussed in the core-libs-dev mailing list message “FYI: new javadoc tag to document system properties” and was introduced in response to JDK-5076751 [“System properties documentation needed in javadocs”].
The {@systemPropery}
Javadoc tag displays its contents as normal text in its generated output and makes the contents available to the Javadoc search introduced with JDK 9. This tag is intended to be used for documenting an application’s system properties.
The following simple class will be used to demonstrate the new JDK 12 Javadoc tag {@systemProperty}
:
package dustin.examples.jdk12.properties; import static java.lang.System.out; /** * Class with sole purpose to illustrate JDK 12's * support for {@literal {@systemProperty}}. */ public class PropertiesDemo { /** * {@systemProperty blog.title} can be specified to * provide a blog title. */ private final static String PROPERTY_NAME = "blog.title"; public static void main(final String[] arguments) { final String property = System.getProperty(PROPERTY_NAME); out.println("Property " + PROPERTY_NAME + ": " + property); } }
The above code example applies {@systemProperty}
to the private
attribute PROPERTY_NAME
. Because the field if private
, the Javadoc tool must be executed with the -private flag to have documentation generated for this field.
The next screen snapshot demonstrates the documentation generated for the simple class using the javadoc
command-line tool included in JDK 12 Early Access Build 12 (which did not have support for {@systemProperty}
.
The red ovals in the previous screen snapshot show that the {@systemProperty}
tag is not handled properly in earlier versions of the JDK. The contents of that tag are NOT displayed and the “search” functionality does not match on the system property name.
The next screen snapshot demonstrates the documentation generated for this same class using the command-line javadoc
that comes with JDK 12 Early Access Build 20.
The green ovals in the previous screen snapshot show that {@systemProperty}
is better supported in Early Access Build 20 of OpenJDK JDK 12. The contents of that tag are correctly displayed in the Javadoc itself and the search capability now matches on the system property name.
The addition of {@systemProperty}
potentially makes it easier for developers to find relevant descriptions of system properties for an application among Javadoc-generated documentation. The aforementioned post “FYI: new javadoc tag to document system properties” discusses other Javadoc enhancements that could possibly be made to take advantage of this tag. The potential enhancements include “a ‘summary page’ that lists all the system properties”, adding “information regarding the ‘scope’ of the definition”, and allowing “a short description to be included in the {@systemProperty}
tag” that “could be included in the search index, the A-Z index, and the summary page.”
The Jonathan Gibbons FYI mailing list message that introduces {@systemProperty}
also spells out its recommended usage:
Where should the tag be used? The tag should be used in the text of the defining instance of the property. This is where the characteristics of the system property are described, which may include information like: “what is the property for”, “how and when is it set”, “can it be modified”, and so on.
The addition of {@systemProperty}
to the Javadoc tool with JDK 12 Early Access Build 20 is a minor thing, but will allow developers to make documentation of important system properties more readily accessible for fellow developers.
Published on Java Code Geeks with permission by Dustin Marx, partner at our JCG program. See the original article here: JDK 12 Javadoc Tag for System Properties Opinions expressed by Java Code Geeks contributors are their own. |