寻找liquibase的jdbc驱动程序类问题



下面是我的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 DocumentsPROJECTSDataSourcelibliquibase-2.0.2.jar;
G:My DocumentsPROJECTSDataSourcelibhsqldb-2.2.5.jar;;
G:My DocumentsPROJECTSDataSourcedbchangelogdb.changelog-1.0.xml;
G:My DocumentsPROJECTSDataSourcedbchangelogdb.changelog-master.xml

但是updateDatabase抛出以下异常:

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

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

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

这是hsqldb驱动程序的名称吗?show org.hsqldb.jdbc.JDBCDriver.

已经指出,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>

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>

相关内容

  • 没有找到相关文章

最新更新