2

这是我的 ant xml 文件的示例:

<!--A reference to the classpath that contains the database driver, liquibase.jar, and the changelog.xml file-->
<path id="liquibase.classpath.id">
   <pathelement location="${PROJECT_DIR}/lib/liquibase-2.0.2.jar"/>
   <pathelement location="${jdbc.classpath}"/>
   <fileset dir="${PROJECT_DIR}/db/changelog" includes="db.changelog*.xml"/>
</path>

<pathconvert refid="liquibase.classpath.id" property="liquibase.classpath.id.text" />
<echo message="${liquibase.classpath.id.text}"  />

<updateDatabase loglevel="debug"
        changeLogFile="${db.changelog.file}"
        driver="${jdbc.driver}"
        url="${jdbc.url}"
        username="${database.username}"
        password="${database.password}"
        dropFirst="false"
        classpathref="liquibase.classpath.id"
        />

<echo message="${liquibase.classpath.id.text}" />按预期得到以下输出:

G:\My Documents\PROJECTS\DataSource\lib\liquibase-2.0.2.jar;
G:\My Documents\PROJECTS\DataSource\lib\hsqldb-2.2.5.jar;;
G:\My Documents\PROJECTS\DataSource\db\changelog\db.changelog-1.0.xml;
G:\My Documents\PROJECTS\DataSource\db\changelog\db.changelog-master.xml

updateDatabase抛出以下异常:

java.lang.ClassNotFoundException: org.hsqldb.jdbc.JDBCDriver

我究竟做错了什么?请告诉我。

4

3 回答 3

0

正如已经指出的,JDBC 驱动程序应该是org.hsqldb.jdbc.JDBCDriver。我认为您的第二个问题是 ANT 找不到您的 hsqldb jar 文件。你绝对确定路径是正确的?

这是我的工作示例(我将类路径管理委托给ivy插件)。

liquibase.properties

url=jdbc:hsqldb:file:build/testdb
driver=org.hsqldb.jdbc.JDBCDriver
username=sa
password=""

构建.xml

<project basedir="." default="build" xmlns:ivy="antlib:org.apache.ivy.ant">

    <!--
    ====================
    Properties and paths
    ====================
    -->
    <property file="liquibase.properties" prefix="db"/>
    <property name="build.dir" location="build"/>
    <property name="db.changelog.file" location="src/scottTiger.xml"/>

    <!--
    =======
    Targets
    =======
    -->
    <target name="init" description="Download 3rd party dependencies">
        <ivy:resolve/>
        <ivy:cachepath pathid="ant.path" conf="ant"/>

        <mkdir dir="${build.dir}"/>
    </target>

    <target name="build" depends="init" description="Create the database">
        <taskdef resource="liquibasetasks.properties" classpathref="ant.path"/>

        <fail unless="db.changelog.file">db.changelog.file not set</fail>
        <fail unless="db.url">db.url not set</fail>
        <fail unless="db.driver">db.driver not set</fail>
        <fail unless="db.username">db.username not set</fail>
        <fail unless="db.password">db.password not set</fail>

        <updateDatabase
            changeLogFile="${db.changelog.file}"
            driver="${db.driver}"
            url="${db.url}"
            username="${db.username}"
            password="${db.password}"
            promptOnNonLocalDatabase="false"
            dropFirst="false"
            classpathref="ant.path"
        />

    </target>

    <target name="clean" description="Cleanup all built files">
        <delete dir="${build.dir}"/>
    </target>

    <target name="clean-all" depends="clean">
        <ivy:cleancache/>
    </target>

</project>

常春藤.xml

Build 配置为下载最新的发布版本,可从 Maven Central 获得

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="scott-tiger"/>
    <configurations defaultconfmapping="ant->default">
        <conf name="ant" description="Ant build dependencies"/>
    </configurations>
    <dependencies>
        <dependency org="org.liquibase" name="liquibase-core" rev="latest.release"/>
        <dependency org="org.hsqldb" name="hsqldb" rev="latest.release"/>
    </dependencies>
</ivy-module>
于 2011-09-18T13:23:24.400 回答
0

我看不到您在哪里定义 的值jdbc.driver,但类名应该是org.hsqldb.jdbc.JDBCDriver,而不是org.hsqldb.jdbcDriver

于 2011-09-18T00:37:29.010 回答
0

那是hsqldb驱动的名字吗?我看过的文档显示 org.hsqldb.jdbc.JDBCDriver。

于 2011-09-18T00:38:42.977 回答