maven hbm2ddl 的简单设置
我正在设置 maven 来获取带注释的 java 类并生成一些 DDL,这些 DDL 根据数据库而变化。有更好的方法吗?看来我应该能够过滤 hbm2ddl 插件的输入(作为管道的一部分),而不是告诉它对资源过滤的输出进行操作(然后我必须从最终的 jar 中过滤掉它)。
我正在过滤我的 hibernate.cfg.xml 文件以根据本地开发人员的设置替换环境属性:
<build>
<filters>
<filter>${user.home}/datamodel-build.properties</filter>
</filters>
<resources><resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource></resources>
</build>
然后我在输出上运行 hbm2ddl
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
...
<configuration>
<componentProperties>
<configurationfile>target/classes/com/myOrg/datamodel/hibernate.cfg.xml</configurationfile>
</plugin>
然后我必须从我的生产 jar 中过滤掉 hibernate.cfg.xml 因为我不想发布与我的内部开发环境相关的任何内容。
I am setting up maven to take annotated java classes and produce some DDL which varies depending on the database. Is there a better way to do this? It seems like I should be able to filter the input to the hbm2ddl plugin (as part of a pipeline) rather than tell it to operate on the output of resource filtering (which I then must filter out of my final jar).
I am filtering my hibernate.cfg.xml file to substitute environment properties based on the local developer's setup:
<build>
<filters>
<filter>${user.home}/datamodel-build.properties</filter>
</filters>
<resources><resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource></resources>
</build>
Then I run hbm2ddl on the output
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
...
<configuration>
<componentProperties>
<configurationfile>target/classes/com/myOrg/datamodel/hibernate.cfg.xml</configurationfile>
</plugin>
I then must filter out the hibernate.cfg.xml from my production jar since I don't want to ship anything related to my internal dev environment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有同样的问题,这是我解决的方法。我使用一个单独的database.properties 文件来保存连接详细信息,并且我不过滤任何XML 文件。
这个单独的database.properties 文件被过滤,但由于它是位于
/src/main/test
中的test 资源,因此不会被放入最终工件中。然后我告诉 hbm2ddl 在哪里可以找到它,如下所示:希望它能有所帮助......
I have this same issue and here is how I solved it. I use have a separate database.properties file that holds the connection details and I don't filter any of my XML files.
This seperate database.properties file gets filtered, but since it is a test resource located in
/src/main/test
it doesn't get put into the final artifact. I then tell hbm2ddl where to find it as follows:Hope it helps anyway....