Maven 2 maven hbm2ddl的简单设置

Maven 2 maven hbm2ddl的简单设置,maven-2,build,hbm2ddl,Maven 2,Build,Hbm2ddl,我正在设置maven以获取带注释的java类并生成一些DDL,这些DDL根据数据库的不同而变化。有更好的方法吗?看起来我应该能够过滤hbm2ddl插件的输入(作为管道的一部分),而不是告诉它操作资源过滤的输出(然后我必须过滤掉最后一个jar) 我正在筛选hibernate.cfg.xml文件,以根据本地开发人员的设置替换环境属性: <build> <filters> <filter>${user.home}/datamodel-buil

我正在设置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>

${user.home}/datamodel-build.properties
src/main/resources
真的
然后在输出上运行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>

org.codehaus.mojo
hibernate3 maven插件
...
target/classes/com/myOrg/datamodel/hibernate.cfg.xml

然后,我必须从我的生产jar中过滤掉hibernate.cfg.xml,因为我不想发布任何与我的内部开发环境相关的内容。

我也有同样的问题,下面是我如何解决它的。我使用单独的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>

hbm2ddl
JPA配置
src/test/resources/database.properties
myapp核心
创建-${database.vendor}-schema.sql
真的
假的
假的

希望它能有所帮助……

我也有同样的问题,下面是我如何解决的。我使用单独的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>

hbm2ddl
JPA配置
src/test/resources/database.properties
myapp核心
创建-${database.vendor}-schema.sql
真的
假的
假的

希望它能有所帮助……

只是为了确保我理解问题所在,DDL的哪些部分会改变(一个简单的例子就足够了)?主要是数据库连接/用户名/方言。我想我有一个解决方案,我现在意识到它可以与hibernate.cfg.xml分开。(只是等着让它全部工作起来)我仍然更喜欢使用maven过滤器,尽管这似乎会使构建矩阵更容易。实际上,我不明白当前解决方案的问题:SIt似乎有太多的步骤,我认为您不能同时过滤和排除同一资源。我正在寻找一种方法,为hibernate-3插件提供输入cfg.xml文件的过滤视图(使用maven过滤器)。我想我只是希望这样的东西会存在,但它似乎不存在。为了确保我理解这个问题,DDL的哪些部分会改变(一个简单的例子可能就足够了)?主要是数据库连接/用户名/方言。我想我有一个解决方案,我现在意识到它可以与hibernate.cfg.xml分开。(只是等着让它全部工作起来)我仍然更喜欢使用maven过滤器,尽管这似乎会使构建矩阵更容易。实际上,我不明白当前解决方案的问题:SIt似乎有太多的步骤,我认为您不能同时过滤和排除同一资源。我正在寻找一种方法,为hibernate-3插件提供输入cfg.xml文件的过滤视图(使用maven过滤器)。我想我只是希望这样的事情会存在,但似乎没有。