什么是 package-info.java 以及如何将其添加到我的项目中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31958948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is package-info.java and how can I add it to my project?
提问by yb3prod
When I run Checkstyle over my Spring project it says:
当我在 Spring 项目上运行 Checkstyle 时,它说:
- Missing package-info.java file.
- what is package-info.javaand how is it useful?
- how can I deal with this message?
- 什么是package-info.java以及它有什么用处?
- 我该如何处理这条消息?
采纳答案by Jordi Castilla
Is used to store javadoc description. You can find it at 7.4.1. Named Packagesof the The Java? Language Specification:
用于存储javadoc 描述。您可以在7.4.1找到它。命名包中的Java的?语言规格:
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.
建议
package-info.java
,如果存在,则代替package.html
javadoc 和其他类似的文档生成系统。如果此文件存在,文档生成工具应在package-info.java
. 通过这种方式,package-info.java
成为包级注释和文档的唯一存储库。如果将来需要添加任何其他程序包级别的信息,则此文件应证明是此信息的方便位置。
An example:
一个例子:
/**
* Info about this package doing something for package-info.java file.
*/
package your.project.doSomething;
UPDATEfrom here
从这里更新
Help adding package-info.java to your packages
帮助将 package-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.
虽然您可以手动将 package-info.java 文件添加到您的包中(就像您可以手动创建 Java 类一样),但 IDE 通常会为您提供在每次创建新包时包含 package-info.java 文件的选项. Eclipse(如下所示)在新建 Java 包创建向导中提供了一个简单(并且经常被忽略)的复选框。