使用liquibase,ant查找jdbc驱动程序类问题

时间:2011-09-17 13:08:43

标签: ant jdbc classnotfoundexception liquibase

以下是我的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

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

3 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

这是hsqldb的驱动程序的名称吗?我见过的文档是org.hsqldb.jdbc.JDBCDriver。

答案 2 :(得分: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=""

的build.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>

的ivy.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>