ant - Liquibase 作为 ant 任务 : relative path to changelogs. 找不到 xml

标签 ant liquibase

我使用 2.0.5 版本的 Liquibase 来测试数据库迁移。目前,如果我定义 changeLogFile属性为updateDatabase任务为 <updateDatabase changeLogFile="${changeLogFile}""${changeLogFile}"liquibase.properties 中指定作为changeLogFile=com/db/master.changelog.xml , 文件 master.changelog.xml 不会被发现。

我使用 Eclispe 和 ant standalone 启动了一个 ant 任务。

所以我将以下修复程序与 ${basedir}/**src**/ 结合使用:

<updateDatabase changeLogFile="${basedir}/src/${changeLogFile}"

但如果没有这种肮脏的解决方案,我会很高兴。

我尝试使用/bin 目录指定 XML 文件的类路径

<fileset dir="bin">        <include name="**/*.xml" />    </fileset>

但是出现了很多异常,所以我把这 block 注释掉了。

我做错了什么?

liquibase.properties文件包含:

changeLogFile=com/db/master.changelog.xml
driver=org.h2.Driver
url=jdbc:h2:tcp://localhost/testhiberliq
username=sa
password=

#for diff between two databases
baseUrl=jdbc:h2:tcp://localhost/testhiberliq
baseUsername=sa
basePassword=

dropFirst=false
tag=version 1.4
outputFile=outputFile.xml
outputDiffFile=outputFile.txt

NewFile1.xml (用作 build.xml ):

<?xml version="1.0" encoding="UTF-8"?>

<project name="liquibase-sample">

    <property file="liquibase.properties" />

    <path id="lib.path">
        <fileset dir="lib">
            <include name="**/*.jar" />
        </fileset>
    <!--    <fileset dir="bin">
            <include name="**/*.xml" />
        </fileset> -->
    </path>

    <taskdef resource="liquibasetasks.properties">
        <classpath refid="lib.path" />
    </taskdef>

    <target name="update-database">
        <!--       <taskdef name="updateDatabase" 
        classpathref="lib.path" />-->
        <updateDatabase changeLogFile="${basedir}/src/${changeLogFile}" driver="${driver}" url="${url}" username="${username}" password="${password}" dropFirst="${dropfirst}" classpathref="lib.path" />
    </target>

</project>

master.changelog.xml :

<?xml version="1.0" encoding="UTF-8"?> 
<databaseChangeLog 
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog/1.9" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog/1.9
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-1.9.xsd"> 

  <include file="changelog/included.changelog.xml" relativeToChangelogFile="true"/> 
  <include file="changelog/included2.changelog.xml" relativeToChangelogFile="true"/> 
  <include file="changelog/included3.changelog.xml" relativeToChangelogFile="true"/> 

</databaseChangeLog> 

和目录树:

I:.
│   .classpath
│   .project
│   liquibase.properties
│   NewFile.xml
│   NewFile1.xml
│   outputFile.txt
│   outputFile.xml
│
├───.settings
│       org.eclipse.jdt.core.prefs
│
├───bin
│   │   hibernate.cfg.xml
│   │
│   ├───com
│   │   └───db
│   │       │   master.changelog.xml
│   │       │
│   │       └───changelog
│   │               included.changelog.xml
│   │               included2.changelog.xml
│   │               included3.changelog.xml
│   │
│   └───testproject
│       │   Main.class
│       │
│       └───database
│           │   DatabaseDAO.class
│           │
│           └───pojo
│                   Users.class
│
├───lib
│       h2-1.3.168.jar
│       liquibase.jar
│
└───src
    │   hibernate.cfg.xml
    │
    ├───com
    │   └───db
    │       │   master.changelog.xml
    │       │
    │       └───changelog
    │               included.changelog.xml
    │               included2.changelog.xml
    │               included3.changelog.xml
    │
    └───testproject
        │   Main.java
        │
        └───database
            │   DatabaseDAO.java
            │
            └───pojo
                    Users.java

最佳答案

该任务将从类路径中检索更改日志文件。您需要将运行时根目录添加到路径中,如下所示:

<path id="lib.path">
    ..
    ..
    <pathelement location="bin"/>
</path>

并按如下方式更改任务:

<updateDatabase changeLogFile="com/db/master.changelog.xml" ...

并且主变更日志文件还需要各个变更文件的完整路径:

<databaseChangeLog .. 

  <include file="com/db/changelog/included.changelog.xml"/> 
  <include file="com/db/changelog/included2.changelog.xml"/> 
  <include file="com/db/changelog/included3.changelog.xml"/> 

</databaseChangeLog> 

在运行时,liquibase 查看本地目录或类路径中列出的 jar 和目录。

为什么这么复杂?这种方法使更改日志文件能够单独或与您的代码一起打包为 jar 存档。非常有用。

关于ant - Liquibase 作为 ant 任务 : relative path to changelogs. 找不到 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16383616/

相关文章:

java - ant不断重新编译

java - 如何让 Ant 更喜欢链接 JAR 中的类而不是 JDK 类?

spring-boot - liquibase.integration.spring.SpringLiquibase 可从 spring boot 中的 2 个位置错误

java - Liquibase Diff 将 LocalTime 映射到 Binary

java - Liquibase 看不到实体的变化

java - apache ant 无法找到或加载主类 org.apache.tools.ant.launch.Launcher

java - 在centos for java上安装opencv

intellij-idea - 如何使用 Ant + IntelliJ IDEA 进行 OpenJPA 增强

ant - 使用liquibase比较数据库和生成sql脚本