Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is package-info.java and how can I add it to my project?

When I run Checkstyle over my Spring project it says:

- Missing package-info.java file. 
  1. what is package-info.java and how is it useful?
  2. how can I deal with this message?
like image 215
yb3prod Avatar asked Aug 12 '15 07:08

yb3prod


People also ask

What is Package-info Java in JAXB?

package-info. java is a way to apply java annotations at the package level. In this case Jaxb is using package-level annotations to indicate the namespace, and to specify namespace qualification for attributes (source).

What is Package-info Java in Eclipse?

Simply put, package-info is a Java file that can be added to any Java package.


1 Answers

Is used to store javadoc description. You can find it at 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.

An example:

/**  * Info about this package doing something for package-info.java file.  */ package your.project.doSomething; 

Also check this answer

UPDATE from here

Help adding package-info.java to your packages

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

like image 96
Jordi Castilla Avatar answered Sep 29 '22 04:09

Jordi Castilla