mybatis-3/src/main/java/org/apache/ibatis/cache/package-info.java

What’s package-info.java for?

https://www.intertech.com/Blog/whats-package-info-java-for/

mybatis-3/src/main/java/org/apache/ibatis/cache/package-info.java

by Jim White | Jul 3, 2013

In some recent classes, my students have encountered a package-info.java file tucked inside of some of the sample code we get from courseware providers.  “What’s that thing?”, they usually ask.

package-info.java’s purpose

The package-info.java is a Java file that can be added to any Java source package.  Its purpose is to provide a home for package level documentation and package level annotations. Simply create the package-info.java file and add the package declaration that it relates to in the file.  In fact, the only thing the package-info.java file must contain is the package declaration.

 
1
package com.intertech.services;

The package-info.java file above must sit in the com.intertech.services package.

Package Documentation

Prior to Java 5, package level documentation (the documentation shown in Javadocs for a package) was placed in package.html.  Today, the description and other related documentation for a package can be written up in the package-info.java file and it gets used in the production of the Javadocs.  As a demonstration, the example package-info.java…

 
1
2
3
4
5
6
7
8
9
10
/**
* Domain classes used to produce the JSON and XML output for the RESTful services.
* <p>
* These classes contain the JAXB annotations.
*
* @since 1.0
* @author jwhite
* @version 1.1
*/
package com.intertech.cms.domain;

… results in the following Javadocs.

Package Annotations

Perhaps more importantly to today’s annotation driven programmer, the package-info.java file contains package level annotations. An annotation with ElementType.PACKAGE as one of its targets is a package-level annotation and there are many of them.  Using your favorite IDE’s code assistant (shown in Eclipse below) in a package-info.java file and you will find a number package annotation options.

For example, perhaps you want to deprecate all the types in a package. You could annotate each individual type (the classes, interfaces, enums, etc. defined in their .java files) with @Deprecated (as shown below).

 
1
2
3
@Deprecated
public class Contact {
}

Or, you could use the @Deprecated on the package declaration in package-info.java.  This has the effect of deprecating everything in the package in one fell swoop.

 
1
2
@Deprecated
package com.intertech.cms.domain;

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.

Wrap Up
So now you know what that package-info.java file is all about and you know how to use it.

Like to learn more about Java or other Java related topics? Take a look at the Java Training courses that we provide.

Intertech also provides Java Consulting for those looking for some help with development projects. See what we can do for you!

最新文章

  1. Odoo 二次开发教程(五)-新API的介绍与应用
  2. CSS继承总结
  3. Oracle使用经验总结
  4. JVM调优总结10-调优方法
  5. C Primer
  6. 【转】详解spring事务属性
  7. Spring 定时任务 quartz的配置
  8. 完毕port(CompletionPort)具体解释 - 手把手教你玩转网络编程系列之三
  9. 使用 Git 报错 error: src refspec master matches more than one.
  10. html5部分相关
  11. 『备注』GDI+ 绘制文本有锯齿,透明背景文本绘制
  12. [Swift]LeetCode495. 提莫攻击 | Teemo Attacking
  13. Dapp的PVP发模式--magic-maze-2d游戏解读
  14. linux最小化安装后的初始化
  15. Idea checkstyle插件的使用
  16. node升级的正确方法
  17. 2019-03-15-day011-递归生成器
  18. EDA优势
  19. 主流JS库一览
  20. 【动态规划】CDOJ1271 Search gold

热门文章

  1. PHP字符串offset取值特性
  2. VS2017编译Poco1.9.0的64版本
  3. python中的数据类型与json的数据类型之间的转化
  4. STL——序列式容器
  5. 一个汉字转拼音的php类
  6. 使用JDBC插入数据到ORACLE,使用标识列自增列
  7. 使用kendynet构建异步redis访问服务
  8. 【抓包分析】 charles + 网易mumu 模拟器数据包
  9. 【读书笔记-数据挖掘概念与技术】数据仓库与联机分析处理(OLAP)
  10. mysql的root的权限被控制无法授权