什么是 package-info.java 以及如何将它添加到我的项目中?
What is package-info.java and how can I add it to my project?
当我 运行 检查我的 Spring 项目时,它说:
- Missing package-info.java file.
- 什么是 package-info.java 它有什么用?
- 我该如何处理这条消息?
用于存放javadoc描述。您可以在 7.4.1. Named Packages of the The Java® Language Specification:
找到它
It is recommended that package-info.java
, if it is present, take the place of package.html
for javadoc and other similar documentation generation systems. If this file is present, the documentation generation tool should look for the package documentation comment immediately preceding the (possibly annotated) package declaration in package-info.java
. In this way, package-info.java
becomes the sole repository for package-level annotations and documentation. If, in future, it becomes desirable to add any other package-level information, this file should prove a convenient home for this information.
一个例子:
/**
* Info about this package doing something for package-info.java file.
*/
package your.project.doSomething;
Also check this answer
更新 from here
帮助添加包-info.java到你的包
While you can add the package-info.java file to your packages by hand (just as you can create Java classes by hand), IDE’s often offer you the option to include a package-info.java file each time you create a new package. Eclipse, shown below, offers a simple (and often overlooked) checkbox in the New Java Package creation wizard.
当我 运行 检查我的 Spring 项目时,它说:
- Missing package-info.java file.
- 什么是 package-info.java 它有什么用?
- 我该如何处理这条消息?
用于存放javadoc描述。您可以在 7.4.1. Named Packages of the The Java® Language Specification:
找到它It is recommended that
package-info.java
, if it is present, take the place ofpackage.html
for javadoc and other similar documentation generation systems. If this file is present, the documentation generation tool should look for the package documentation comment immediately preceding the (possibly annotated) package declaration inpackage-info.java
. In this way,package-info.java
becomes the sole repository for package-level annotations and documentation. If, in future, it becomes desirable to add any other package-level information, this file should prove a convenient home for this information.
一个例子:
/**
* Info about this package doing something for package-info.java file.
*/
package your.project.doSomething;
Also check this answer
更新 from here
帮助添加包-info.java到你的包
While you can add the package-info.java file to your packages by hand (just as you can create Java classes by hand), IDE’s often offer you the option to include a package-info.java file each time you create a new package. Eclipse, shown below, offers a simple (and often overlooked) checkbox in the New Java Package creation wizard.