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证书申请(满满的干货) 单向 / 双向认证 ...
随机推荐
- LabelTTF 设置字体时的问题
使用cc.LabelTTF:create(txt, fontname, fontsize); 字体没能显示出来, 这里使用的是系统字体, 比如我使用"微软雅黑", 作为font ...
- linux 端口占用情况
1,查看8010端口是否被占用 [root@cloud ~]# netstat -an|grep 8010 tcp 0 0 0.0.0.0:8010 0.0.0.0:* LISTEN 2,查看8010 ...
- Struts2开发模式漏洞
当Struts2中的devMode模式设置为true时,存在严重远程代码执行漏洞.如果WEB服务以最高权限运行时,可远程执行任意命令,包括远程控制服务器. 如果为受影响的版本,建议修改配置文件stru ...
- Memcache未授权访问漏洞
Memcached 分布式缓存系统,默认的 11211 端口不需要密码即可访问,黑客直接访问即可获取数据库中所有信息,造成严重的信息泄露. 0X00 Memcache安装 1. 下载Mencache的 ...
- SpringBoot(九)-- SpringBoot JDBC
1.属性配置文件(application.properties) # type 可以修改连接池类型,默认采用Tomcat的连接池 # spring.datasource.type=com.alibab ...
- SaltStack 使用 Jinja2 模板
Jinja2 是基于 python 的一个模板引擎,如下,使用 Jinja2 实现根据不同的操作系统分发不同的文件: [root@localhost ~]$ cat /srv/salt/test.sl ...
- Kafka 0.11客户端集群管理工具AdminClient
很多用户都有直接使用程序API操作Kafka集群的需求.在0.11版本之前,kafka的服务器端代码(即添加kafka_2.**依赖)提供了AdminClient和AdminUtils可以提供部分的集 ...
- JTAG、JLink、ULINK、ST-LINK仿真器区别(转)
首先要了解一下JTAG. JTAG协议 JTAG(Joint Test Action Group,联合测试行动小组)是一种国际标准测试协议(IEEE 1149.1兼容),主要用于芯片内部测试.现在多数 ...
- iOS9下App Store新应用提审攻略
博文转载 CocoaChina 文/文公子 公子在第十讲中提到应用更新时需要注意的细节和苹果便捷通道的利用.今天,公子将进一步深扒iTunes Connect的面纱,为大家呈现新应用在提审前需要准备的 ...
- iOS 静态库和动态库(库详解)
什么是库 ? 库就是程序代码的集合,将N个文件组织起来,是共享程序代码的一种方式.库从本质上来说是一种可执行代码的二进制格式,可以被载入内存中执行. 库的分类 开源库:源代码是公开的,可以看到每个实现 ...