【问题标题】:Understanding the Maven Build Process了解 Maven 构建过程
【发布时间】:2013-10-22 17:15:37
【问题描述】:

我有一个正在为学校工作的项目,该项目使用 hibernate 来实现 jpa。我的问题是,如果在休眠属性文件中我关闭了模式生成,并且我想手动更新模式(我的 ddl 文件)并将我的模式与应用程序一起部署,我需要在我的 @ 中包含什么987654321@ 标记将架构作为部署内容的一部分?

在 src/main/resources 下我有一个 ddl 目录,其中包含表创建脚本。

【问题讨论】:

    标签: java hibernate maven jakarta-ee


    【解决方案1】:

    在构建过程中你需要使用sql-maven-plugin来执行sql

    类似

    <build>
        [...]
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sql-maven-plugin</artifactId>
            <version>1.5</version>
    
            <dependencies>
              <!-- specify the dependent jdbc driver here -->
              <dependency>
                <groupId>postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>8.1-407.jdbc3</version>
              </dependency>
            </dependencies>
    
            <!-- common configuration shared by all executions -->
            <configuration>
              <driver>org.postgresql.Driver</driver>
              <url>jdbc:postgressql://localhost:5432:yourdb</url>
              <username>postgres</username>
              <password>password</password>
              <!-- You can comment out username/password configurations and
                   have maven to look them up in your settings.xml using ${settingsKey}
              -->
              <settingsKey>sensibleKey</settingsKey>
              <!--all executions are ignored if -Dmaven.test.skip=true-->
              <skip>${maven.test.skip}</skip>
            </configuration>
    
            <executions>
              <execution>
                <id>create-data</id>
                <phase>process-test-resources</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <orderFile>ascending</orderFile>
                  <fileset>
                    <basedir>${basedir}</basedir>
                    <includes>
                      <include>src/test/sql/test-data2.sql</include>
                    </includes>
                  </fileset>
                </configuration>
              </execution>
    
          </plugin>
          [...]
        </plugins>
        [...]
      </build>
    

    根据您的数据库更改配置

    【讨论】:

    • 构建发生在我的开发机器上,但应用程序实际上被部署到其他地方的服务器上,那么它是如何工作的?
    • 生产数据库部署应该独立于构建过程,它应该与app bootstrap绑定,这更适合测试db创建测试执行,如果你仍然想这样做只需更改数据库url和其他配置,它将指向远程机器
    猜你喜欢
    • 2013-07-15
    • 1970-01-01
    • 2017-10-26
    • 1970-01-01
    • 2014-04-20
    • 2016-01-08
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    相关资源
    最近更新 更多