Maven:将 package-info.java 编译为 package-info.class?

发布于 2024-11-25 11:38:02 字数 474 浏览 0 评论 0原文

我的包中有 package-info.java,Hibernate 需要它来实现某些功能(编程实体扫描)。

但是,mvn package 不会导致 package-info.class 位于 classes/ 中,因此不在工件中。

我怎样才能强迫这种情况发生?

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"

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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

彼岸花似海 2024-12-02 11:38:02

为 javac 提供 -Xpkginfo:always 选项。

请参阅

Give -Xpkginfo:always option to javac.

See the

混浊又暗下来 2024-12-02 11:38:02

错误是 package-info.java 必须具有任何带有 Retention=RUNTIME 的注释才能编译成类。否则,JDK 6 会忽略它。
我使用了 @Deprecated,这是 Java SE 中唯一的一个(并且我不想仅仅因为这个而引入注释)。

@Deprecated
package cz.zizka.ondra.packageinfo.test

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
征﹌骨岁月お 2024-12-02 11:38:02

替代解决方案(受到 zbyszek 答案的启发)是将其添加到您的 pom.xml 中:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerArgs>
                    <arg>-Xpkginfo:always</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

Alternative solution (inspired by zbyszek's answer) is to add this to your pom.xml:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <compilerArgs>
                    <arg>-Xpkginfo:always</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>
悸初 2024-12-02 11:38:02

在 Maven 3 中工作正常;不知道2.是否有可能package-info.java中的包声明丢失或错误?

Works correctly in Maven 3; don't know about 2. Is it possible that the package declaration in package-info.java is missing or wrong?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文