gpt4 book ai didi

java - 什么是 package-info.java,如何将它添加到我的项目中?

转载 作者:IT老高 更新时间:2023-10-28 13:50:08 25 4
gpt4 key购买 nike

当我在我的 Spring 项目上运行 Checkstyle 时,它​​会说:

- Missing package-info.java file.
  1. 什么是package-info.java,它有什么用处?
  2. 我该如何处理这条消息?

最佳答案

用于存储javadoc描述。您可以在 7.4.1. Named Packages 上找到它的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

帮助将 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.

enter image description here

关于java - 什么是 package-info.java,如何将它添加到我的项目中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31958948/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com