在编译时执行此操作:
听起来像是 Maven 的工作filters http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html and/or profiles http://maven.apache.org/guides/introduction/introduction-to-profiles.html
注意:小心 liquibase 和任何“标记”替换... liquibase 存储应用变更集的 CRC
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<filters>
<filter>src/main/filters/liquibase.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>liquibase.xml</include>
</includes>
</resource>
</resources>
</build>
</project>
/src/main/filters/liquibase.properties
table.name=TABLE_NAME
column1.name=COLUMN1_NAME
column1.length=10
column2.name=COLUMN2_NAME
/src/main/resources/liquibase.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog logicalFilePath="liquibase.xml" xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<changeSet author="me" id="changeSetId1">
<comment>Test</comment>
<createTable tableName="${table.name}">
<column name="id" type="int" />
<column name="${column1.name}" type="varchar(${column1.length})" />
<column name="${column2.name}" type="int" />
</createTable>
</changeSet>
</databaseChangeLog>
EDIT: A typical http://www.liquibase.org/documentation/maven/调用(使用filtered http://maven.apache.org/guides/getting-started/index.html#How_do_I_filter_resource_files资源)看起来像这样:mvn resources:resources liquibase:update
或者更优选地使用配置文件...mvn resources:resources liquibase:update -P<profile_name>
EDIT2:这种定义列的方式有一个很大的优点。您可以使用此属性(例如:column1.length)值(例如:10)来验证every层:Hibernate、DAO、WEB、faces、JavaScript。只需在需要验证的每个地方使用此属性即可。如果需要的话,甚至在 i18n/messages.properties 中(例如:input1.validation=不超过 ${column1.length} 个字母。)。
唯一的复杂之处是,如果您需要更改此值,您需要提供正确的 liquibase 更新/回滚脚本。有时可以更改值并设置新的 liquibase 校验和(安全操作,例如增加 varchar 长度),但有时您需要使用新属性/值创建安全更新更改脚本。