第二次使用maven的liqubase插件在项目启动的时候自动建表,记录一下,备忘:
使用eclipse的maven插件:
changelog.xml
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="xxx-2015-6-30-1" author="jiangyu">
<sqlFile path="city_table_struct.sql" encoding="UTF-8" relativeToChangelogFile="true" />
</changeSet>
<changeSet id="xxx-2015-6-30-2" author="jiangyu">
<sqlFile path="city_init_data.sql" encoding="UTF-8" relativeToChangelogFile="true" />
</changeSet>
</databaseChangeLog>
pom文件配置:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.5</version>
<configuration>
<changeLogFile>src/main/resources/city/cityinit.changelog.xml</changeLogFile>
<driver>${dataSource.project.driverClass}</driver>
<url>${dataSource.project.jdbcURL}</url>
<username>${dataSource.project.user}</username>
<password>${dataSource.project.password}</password>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin><pre name="code" class="html"><pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on
the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<versionRange>[3.0.5,)</versionRange>
<goals>
<goal>update</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
本文记录了如何利用Maven的Liubase插件在Eclipse环境下,实现项目启动时自动创建数据库表的操作。通过配置changelog.xml和pom.xml文件,可以便捷地管理数据库变更。

494

被折叠的 条评论
为什么被折叠?



