package-info.java https://www.intertech.com/Blog/whats-package-info-java-for/
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/的更多相关文章
- https://www.nginx.com/blog/introduction-to-microservices/
https://www.nginx.com/blog/introduction-to-microservices/
- Java学习笔记5---命令行下用javac,java编译运行含package语句的类
对于笔记3中的HelloWorld程序,编译时只要输入javac HelloWorld.java即可生成类文件:再用java HelloWorld即可运行. 如果源程序使用了包声明,编译运行时要使用某 ...
- Java之旅_面向对象_包(Package)
http://www.runoob.com/java/java-package.html 包的作用: 1.把功能相似或相关的类或接口组织在同一个包中,方便类的查找和使用. 2.如同文件夹一样,包也采用 ...
- 搬家至独立博客 https://www.imzjy.com/blog/
欢迎访问 https://www.imzjy.com/blog/
- Java https认证的坑
https单向认证的服务端证书不是权威机构颁发的,网上找了点代码不对https证书进行认证后,报如下异常 javax.net.ssl.SSLHandshakeException: Received f ...
- 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
- java https
1. 异常突现 在这普通的一天,我写普通的代码,却突然收到不普通的报警 javax.net.ssl.SSLHandshakeException: server certificate change i ...
- ### 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 ...
- Java Https双向验证
CA: Certificate Authority,证书颁发机构 CA证书:证书颁发机构颁发的数字证书 参考资料 CA证书和TLS介绍 HTTPS原理和CA证书申请(满满的干货) 单向 / 双向认证 ...
随机推荐
- Python对象(上)
Python是一门面向对象的语言,在Python中一切都是对象,函数是对象,类型也是对象. 下面就看看Python中对象相关的内容. Python对象基本概念 Python对象有三个基本的要素: 身份 ...
- iOS - 解决Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named
1 本来cocopods没有问题,最近创建项目,利用cocopods导入第三方库的时候,出现如下错误: [!] Unable to add a source with url `https://gi ...
- TTL值
我们在解析域名时经常出现 TTL 这个字段,里面默认写的是 10 分钟. 另外,有时候我们 ping 某域名或 IP 的时候,会出现 TTL= XXX. 一.什么是域名的 TTL 值? TTL(Tim ...
- 查询mssql 密码
select name,password from syslogins Select master.dbo.fn_varbintohexstr(password_hash) from sys.sql_ ...
- vmware 安装 Mac OS X 10.9 Mavericks
This guide shows how to install fresh OS X 10.9 Mavericks on VMware workstation with Windows 7 or Wi ...
- VMware按装ISO
破解码 vmware12 5A02H-AU243-TZJ49-GTC7K-3C61N vmware14CG54H-D8D0H-H8DHY-C6X7X-N2KG6 创建虚拟机 也可以选第三个直接选择Ce ...
- thinkphp3.2 实现点击图片或文字进入内容页
首先要先把页面渲染出来,http://www.mmkb.com/weixiang/index/index.html <div class="main3 mt"> < ...
- 【linux】 scrapy : Could not find a version that satisfies the requirement Twisted>=13.1.0 (from Scrapy) (from versions: )
centos7 + python3 安装 scrapy 时候报错,错误信息如下: Could not find a version that satisfies the requirement Twi ...
- 【Linux】python 2.x 升级 python3.x 之后 yum命令出现except OSError, e: ^ SyntaxError: invalid syntax
python2.7升级到python3.6.4 文章链接 : https://zhuanlan.zhihu.com/p/33660059 我在服务器上.把linux默认安装的python2.7 升级 ...
- spring mvc 跨域请求处理——spring 4.2 以上
Controller method CORS configuration You can add to your @RequestMapping annotated handler method a ...