我正在设置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,因为我不想发布任何与我的内部开发环境相关的东西。
发布于 2011-01-05 00:03:47
我也有同样的问题,下面是我是如何解决它的。我使用一个单独的database.properties文件来保存连接细节,并且我不过滤任何XML文件。
这个单独的database.properties文件会被过滤掉,但是因为它是位于/src/main/test中的一个测试资源,所以它不会被放入最终的工件中。然后我告诉hbm2ddl在哪里可以找到它,如下所示:
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>jpaconfiguration</implementation>
</component>
</components>
<componentProperties>
<propertyfile>src/test/resources/database.properties</propertyfile>
<!-- Gives the name of the persistence unit as defined in persistence.xml -->
<persistenceunit>myapp-core</persistenceunit>
<!-- Tells the plugin to send the output to a file -->
<outputfilename>create-${database.vendor}-schema.sql</outputfilename>
<!-- Pretty Format SQL Code -->
<format>true</format>
<!-- Do not create tables automatically - other plug-ins will handle that -->
<export>false</export>
<!-- Do not print the DDL to the console -->
<console>false</console>
</componentProperties>
</configuration>希望它能帮上忙。
https://stackoverflow.com/questions/3678562
复制相似问题