Why is package-info.java useful?

Socrates picture Socrates · Feb 28, 2014 · Viewed 61.1k times · Source

When I run CheckStyle over my Java project it says Missing package-info.java file. for some classes, but not all of them. I can't really figure out why this message appears only sometimes. Furthermore my project runs perfectly fine without the package-info.java.

What does the package-info.java do? Do I really need it for my Java projects?

Answer

m-szalik picture m-szalik · Feb 28, 2014

It is used to generate javadocs for a package.

/**
* Domain classes used to produce .....
* <p>
* These classes contain the ......
* </p>
*
* @since 1.0
* @author somebody
* @version 1.0
*/
package com.domain;

Will generate package info for com.domain package:

Example result: https://docs.oracle.com/javase/7/docs/api/java/awt/package-summary.html