2013-05-05 70 views
2

我使用Liquibase的2.0.5版本來測試數據庫遷移。目前,如果我定義了changeLogFile屬性爲updateDatabase任務,<updateDatabase changeLogFile="${changeLogFile}""${changeLogFile}"liquibase.properties指定爲changeLogFile=com/db/master.changelog.xml,文件master.changelog.xml被發現。Liquibase作爲一項螞蟻任務:找不到changelogs.xml的相對路徑

我使用Eclispe和ant standalone開始了一個ant任務。

所以我用下面的修復與${basedir}/**src**/

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

但我會沒有這樣一個骯髒的解決方案非常高興。

我嘗試指定XML文件中的類路徑,使用/箱目錄

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

但很多例外的發生,所以我評論了該塊。

我做錯了什麼?

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 

回答

0

任務會從類路徑檢索更新日誌文件。你需要運行時根目錄添加到路徑如下:

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

,並改變任務如下:

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

和碩changelog文件也需要完整的路徑個別變化的文件:

<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查看本地目錄或者在classpath中列出的jar和目錄中。

爲什麼這種複雜性?這種方法可以將更改日誌文件打包爲一個jar文件,無論是單獨執行還是與代碼並行執行。很有用。

+0

嗨馬克奧康納,我只有xml,放在類路徑中,沒有與更改日誌xml exisit罐。如果我嘗試設置「java」類路徑(又名「bin」),那麼會引發很多異常:無法從i中獲取資源:\ workspace \ TestLqbsProject \ bin \ com \ db \ changelog \ included.changelog .xml: java.util.zip。ZipException:打開zip文件時出錯 – 2013-05-06 13:14:17

+0

嗨,馬克奧康再次:-)如果我使用 -tag檢索changelog-xmls的類路徑,則會發生異常。我現在使用位置「bin」的pathelement,所以liquibase螞蟻任務運行!其他更改不需要。非常感謝您的重播 – 2013-05-06 13:30:17