3

私は Liquibase の 2.0.5 バージョンを使用して、データベースの移行をテストしています。現在、task asにchangeLogFile属性を定義し、 asにを指定すると、ファイルが見つかりません。updateDatabase<updateDatabase changeLogFile="${changeLogFile}""${changeLogFile}"liquibase.propertieschangeLogFile=com/db/master.changelog.xmlmaster.changelog.xml

Eclispe と ant スタンドアロンを使用して、ant タスクを開始しました。

したがって、次の修正を使用します${basedir}/**src**/

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

しかし、そのような汚い解決策がなければ、私はとても幸せです。

/bin-directory を使用して、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
4

1 に答える 1

0

このタスクは、クラスパスから変更ログ ファイルを取得します。次のように、ランタイム ルート ディレクトリをパスに追加する必要があります。

<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 アーカイブとしてパッケージ化できます。非常に便利。

于 2013-05-06T11:21:40.547 に答える