Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: Compiling package-info.java to package-info.class?

I have package-info.java in my package, Hibernate wants it for some features (programatic entity scanning).

However, mvn package does not result in package-info.class being in classes/ thus not in the artifact.

How can I force that happening?

mvn -v
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.6.0_26
Java home: /usr/lib/jvm/java-6-sun-1.6.0.26/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.35-30-generic" arch: "amd64" Family: "unix"
like image 474
Ondra Žižka Avatar asked Jul 21 '11 01:07

Ondra Žižka


People also ask

How do you create a package-info class?

Creating a package-info file is fairly simple: we can create it manually or seek IDE help for generating the same. In IntelliJ IDEA, we can right-click on the package and select New-> package-info. java: Eclipse's New Java Package option allows us to generate a package-info.

What is Package-info Java in JAXB?

package-info. java is a way to apply java annotations at the package level. In this case Jaxb is using package-level annotations to indicate the namespace, and to specify namespace qualification for attributes (source).

What is the use of package-info Java?

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.

What is package HTML?

A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another.


2 Answers

Give -Xpkginfo:always option to javac.

See the

  • javac 1.8 documentation

  • javac 17 documentation

like image 161
zbyszek Avatar answered Oct 05 '22 05:10

zbyszek


The error was that the package-info.java must have any annotation with Retention=RUNTIME to compile into a class. Otherwise, JDK 6 omits it.
I used @Deprecated which is the only one in Java SE (and I didn't want to introduce an annotation just because of that).

@Deprecated
package cz.zizka.ondra.packageinfo.test
like image 21
Ondra Žižka Avatar answered Oct 05 '22 05:10

Ondra Žižka