Maven 不编译 target/hibernate3/ generated-sources

发布于 2024-09-02 17:46:19 字数 771 浏览 10 评论 0原文

有人可以告诉我如何配置 maven 来编译 target/hibernate3/ generated-sources 目录中的源代码吗?我已经阅读了 this 和其他帖子,但它们似乎没有解决我的问题(这确实看起来微不足道)。

我使用自下而上的方法 hibernate 配置来生成 cfg.xml、hbm.xml 和 POJO(即从现有数据库模式自动生成完整的 hibernate 配置)。我也只使用标准的 maven 和 hibernate3-plugin 目录布局。然而,当我在命令行中执行mvncompile时,而我的源位于src/main/java中,生成的源位于/target/hibernate3/generate中-sources 仅来自 src/main/java 的内容被编译并复制到 target/classes 中。我不想将源代码生成到 src/main/java 中,因为我希望使用 mvn clean 来清理它们。

我想仅使用命令行插件pom.xml来解决问题。有没有办法配置maven-compiler-plugin来做到这一点?或者还有别的办法吗?

问候并感谢您的任何帮助。

Can someone tell me how to configure maven for it also to compile sources from the target/hibernate3/generated-sources directory? I have already read this and other posts but they don't seem to solve my problem (which indeed seems trivial).

I have used the bottom-up approach hibernate configuration for cfg.xml, hbm.xml and POJO generation (i.e. auto-generated the complete hibernate configuration out of an existing database schema). I'm also only using standard maven and hibernate3-plugin directory layouts. Yet, when executing mvn compile in the command-line while my sources are in the src/main/java and the generated sources in /target/hibernate3/generated-sources only the ones from src/main/java get compiled and copied into target/classes. I wouldn't like to generate sources into src/main/java as I'd like mvn clean to clean them.

I'd like to solve the problem using command-line, plugins and pom.xml only. Is there a way to configure maven-compiler-plugin to do so? Or is there another way?

Regards and thanks for any help.

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

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

发布评论

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

评论(1

暮年 2024-09-09 17:46:19

约定是在 target/ generated-sources/ 中生成代码,因此在您的情况下,我会在 target/ generated-sources/hibernate3 中生成源代码(它是遗憾的是 hibernate3 插件默认不遵循此约定)。无论如何,事情应该有效,实际上,我在 之前的答案确实如此(我重新运行了我的示例项目,它确实有效)。您会成为 MHIBERNATE-104 的受害者吗?老实说,我很困惑。

作为解决方法,您可以使用 Build Helper Maven 插件 及其 < a href="http://mojo.codehaus.org/build-helper-maven-plugin/add-source-mojo.html" rel="nofollow noreferrer">build-helper:add-source 目标是将您的目录添加为源目录。有关配置示例,请参阅用法页面。


我正在使用您在这里建议的 pom,只是没有插入默认的构建生命周期(没有执行)。

这一定是问题的原因:如果 hibernate3:hbm2java 不是构建生命周期的一部分,它就没有机会将输出目录注册为源文件夹。所以 Maven 在“正常构建”期间并不知道它,并且只会忽略它。

The convention is to generate code in target/generated-sources/<generator> so in your case, I would generate sources in target/generated-sources/hibernate3 (it's sad the hibernate3 plugin doesn't follow this convention by default). Anyway, things should work and actually, the POM I posted in this previous answer does (I re-ran my sample project and it definitely works). Could you be a victim of MHIBERNATE-104? Honestly, I'm confused.

As a workaround, you could use the Build Helper Maven Plugin and its build-helper:add-source goal to add your directory as source directory. See the Usage page for a configuration example.


I'm using exactly the pom you proposed here, just not plugged into the default build lifecycle (without executions).

That must be the cause of the problem: if hibernate3:hbm2java isn't part the build lifecycle, it doesn't get the opportunity to register the output directory as source folder. So Maven isn't aware of it during the "normal build" and will just ignore it.

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