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!

package-info.java https://www.intertech.com/Blog/whats-package-info-java-for/的更多相关文章

  1. https://www.nginx.com/blog/introduction-to-microservices/

    https://www.nginx.com/blog/introduction-to-microservices/

  2. Java学习笔记5---命令行下用javac,java编译运行含package语句的类

    对于笔记3中的HelloWorld程序,编译时只要输入javac HelloWorld.java即可生成类文件:再用java HelloWorld即可运行. 如果源程序使用了包声明,编译运行时要使用某 ...

  3. Java之旅_面向对象_包(Package)

    http://www.runoob.com/java/java-package.html 包的作用: 1.把功能相似或相关的类或接口组织在同一个包中,方便类的查找和使用. 2.如同文件夹一样,包也采用 ...

  4. 搬家至独立博客 https://www.imzjy.com/blog/

    欢迎访问 https://www.imzjy.com/blog/

  5. Java https认证的坑

    https单向认证的服务端证书不是权威机构颁发的,网上找了点代码不对https证书进行认证后,报如下异常 javax.net.ssl.SSLHandshakeException: Received f ...

  6. https://www.luogu.org/blog/An-Amazing-Blog/mu-bi-wu-si-fan-yan-ji-ge-ji-miao-di-dong-xi

    https://www.luogu.org/blog/An-Amazing-Blog/mu-bi-wu-si-fan-yan-ji-ge-ji-miao-di-dong-xi

  7. java https

    1. 异常突现 在这普通的一天,我写普通的代码,却突然收到不普通的报警 javax.net.ssl.SSLHandshakeException: server certificate change i ...

  8. ### Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: cn.xiaojian.blog.po.BlogType and java.lang.String ### Cause: java.lang.IllegalArgumentException: ...

    ### Error querying database. Cause: java.lang.IllegalArgumentException: invalid comparison: cn.xiaoj ...

  9. Java Https双向验证

    CA: Certificate Authority,证书颁发机构 CA证书:证书颁发机构颁发的数字证书 参考资料 CA证书和TLS介绍 HTTPS原理和CA证书申请(满满的干货) 单向 / 双向认证 ...

随机推荐

  1. php curl那点事儿

    curl是最常用功能之一初始化句柄 $ch = curl_init(); post 传$data 1. 如果$data是字符串,则Content-Type是application/x-www-form ...

  2. 使用es6使数组的第一项和最后一项就行调换

    let arr = [1, 2, 3,4]; let a = arr.filter((item, index) => { return index > 0 && index ...

  3. 如何将一个项目打成war包?

    如何将一个项目打成war包?进入该项目所在目录jar  -cvf  myProjec.war  myProject

  4. JS使用中碰到的一些问题

    settimeout: 1.setTimeout(function () {//这个则会在1秒后进行弹出1 alert(1); }, 1000); 2.setTimeout(alert(1), 100 ...

  5. 云计算设计模式(六)——命令和查询职责分离(CQRS)模式

    云计算设计模式(六)——命令和查询职责分离(CQRS)模式 隔离,通过使用不同的接口,从操作读取数据更新数据的操作.这种模式可以最大限度地提高性能,可扩展性和安全性;支持系统在通过较高的灵活性,时间的 ...

  6. 写一个自定义的控件接口 C#

    以下是我的测试代码:APP_Code/ucInterface.cs /* APP_Code/ucInterface.cs */ /// <summary> /// Summary desc ...

  7. Spark学习笔记--Spark在Windows下的环境搭建

    本文主要是讲解Spark在Windows环境是如何搭建的 一.JDK的安装 1.1 下载JDK 首先需要安装JDK,并且将环境变量配置好,如果已经安装了的老司机可以忽略.JDK(全称是JavaTM P ...

  8. oracle IMP-00085: 为无界导出文件指定了多个输入文件

    导入按表导出的数据的时候,提示为无界导出文件指定了多个输入文件 命令如下: imp user/user@database file=e:\test.dmp  提示信息: Import: Release ...

  9. requests源码分析

    0.前言 (1) 拆部分reques中感兴趣t的轮子 (2)对一些感兴趣的pythonic写法做一些归纳 1.用object.__setattr__来初始化构造函数 反正我之前就是直接实例对象时把所有 ...

  10. centos6上使用xfs文件系统

    ext4目前也还没有真的支持16TB以上的单分区空间,由于工具的限制,只能创建最大为16T的单分区决定直接用xfs 安装xfs [root@ ~]$ yum install kmod-xfs xfsp ...