Maven 不编译 target/hibernate3/ generated-sources
有人可以告诉我如何配置 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
约定是在
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
目标是将您的目录添加为源目录。有关配置示例,请参阅用法页面。这一定是问题的原因:如果 hibernate3:hbm2java 不是构建生命周期的一部分,它就没有机会将输出目录注册为源文件夹。所以 Maven 在“正常构建”期间并不知道它,并且只会忽略它。
The convention is to generate code in
target/generated-sources/<generator>
so in your case, I would generate sources intarget/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.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.