To compile package-info.java

In Java, the package allows you to specify some annotations. To do this, you have to create a package-info.java file to have the package definition only. For example:

/**
 * This package includes ... classes.
 * @author Yoichiro Tanaka
 */
package jp.eisbahn.foo.bar;

The package-info.java file can be compiled. But, in the case above, the file will not be compiled unfortunately. The reason is that a javac decide to not need it at runtime. Therefore, if you want to get the package-info.class file, you must put any annotation with RUNTIME value.

/**
 * This package includes ... classes.
 * @author Yoichiro Tanaka
 */
@RuntimeAnnotation
package jp.eisbahn.foo.bar;

import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Retention;

@Retention(RetentionPolicy.RUNTIME)
@interface RuntimeAnnotation {}

In the same file, you can define an annotation with a RUNTIME attribute of a RetentionPolicy class. As adding the annotation to your package, the package is needed at runtime. As the result, the file will be compiled by javac.

Trackback URL:



Get Adobe Flash playerPlugin by wpburn.com wordpress themes