Package-info.java documentation
Package-info.java documentation
1. Introduction to pacakge-info.java
A pacakge-info.java is a Java file that can be added to any Java source package. The goal of the pacakge-info.java is to provide either a package-level documentation or a package-level annotation.
In the pacakge-info.java file, the only requirement to contain content is the package statement, such:
Package com. ch. service;
Ii. Package documentation
Before Java 5, the package.html document is generated through JavaDoc. In Java 5 and later versions, the Package Description and related documents can be written into the pacakge-info.java file, it is also used to generate JavaDoc. For example:
- /**
- * Dev1.ch Package Description <br>
- * Tool libraries encapsulated based on the Apache DbUtils library to simplify development
- * @ Author Li Qiang <br>
- * Date: 2015.5.13
- * @ Since 1.7
- * @ Version 1.0
- *
- */
- Package dev1.ch;
The above description is generated through JavaDoc as follows:
Click the link of the dev1.ch package to display:
3. Package comments
Annotations are important to programmers, and pacakge-info.java files contain package-level annotations. We can also use ElementType to customize annotations.
The PACKAGE annotation is of course ElementType. PACKAGE. In addition, there are:
ElementType. TYPE (class, interface, enum)
ElementType. FIELD (instance variable)
ElementType. METHOD ElementType. PARAMETER
ElementType. CONSTRUCTOR
ElementType. LOCAL_VARIABLE
ElementType. ANNOTATION_TYPE (applied to another annotation)
For example, to Deprecate all types in the package, you can annotate each individual type (class, interface, enumeration, etc.) as follows:
- @DEPRECATED
- PUBLIC CLASS CONTACT {
- }
Or you can use the @ Deprecated annotation in the package-info.java package declaration file, which makes everything in the package obsolete.
- @Deprecated
- package dev1.ch.domain;
4. Add the package-info.java to the package
You can manually create a package-info.java file in the package directory, or you can achieve this through Eclipse tools.