0
我有一个项目,我正在为使用hibernate实现jpa的学校开展工作。我的问题是,如果在休眠属性文件中关闭模式生成,并且我想手动更新模式(我的ddl文件),并将我的模式与应用程序一起部署,那么需要在我的<build></build>
中包含什么内容标记将架构作为部署的一部分?了解Maven构建过程
在src/main/resources下我有一个包含表创建脚本的ddl目录。
我有一个项目,我正在为使用hibernate实现jpa的学校开展工作。我的问题是,如果在休眠属性文件中关闭模式生成,并且我想手动更新模式(我的ddl文件),并将我的模式与应用程序一起部署,那么需要在我的<build></build>
中包含什么内容标记将架构作为部署的一部分?了解Maven构建过程
在src/main/resources下我有一个包含表创建脚本的ddl目录。
您将需要使用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>
根据您的数据库
构建恰好我的机器上,但应用程序的更改配置实际上正在部署到其他地方的服务器,那么这是如何工作的? – user1154644
生产数据库的部署应该独立于构建过程,它应该绑定到应用程序的引导程序,这更适合测试数据库的创建,以便测试执行,如果您仍然希望这样做,只需更改数据库url和其他配置,它就会指向到远程机器 –