0
votes

I am trying to run an ant script to deploy changes via liquibase.

<project name="Example" xmlns:liquibase="antlib:liquibase.integration.ant">

    <taskdef 
        resource="liquibase/integration/ant/antlib.xml" 
        uri="antlib:liquibase.integration.ant">

        <classpath path="C:\liquibase\lib\liquibase\"/>

    </taskdef>

  <property name="db.changelog.file" value="C:\projects\lbdemo\trunk\db_v4.xml"/>
  <property name="database.url" value="jdbc:oracle:thin:@mydb:1521:ORCL"/>
  <property name="database.username" value="myuser"/>
  <property name="database.password" value="mypassword"/>
  <property name="database.driver" value="oracle.jdbc.OracleDriver"/>

  <liquibase:database id="my-database" driver="${database.driver}" url="${database.url}" user="${database.username}" password="${database.password}"/>

  <liquibase:updateDatabase databaseref="my-database" changelogfile="${db.changelog.file}"/>

</project>

Installation Paths:

  • Liquibase is installed at: C:\liquibase
  • The JDBC driver is located at: C:\liquibase\ojdbc7.jar

  • Ant is installed at: C:\apache-ant-1.10.1

  • I copied the liquibase.jar into: C:\apache-ant-1.10.1\lib
  • My ANT build file : C:\projects\lbdemo\trunk\build.xml
  • My change file: C:\projects\lbdemo\trunk\db_v4.xml

Tests

  • I am able to successfully run a liquibase update with my change file db_v4.xmls using the Windows command line.

  • I am able to run the ANT build.xml file if I remove all liquibase tags from it.

Error:

I am getting the below error when running the above ANT build:

C:\projects\lbdemo\trunk>ant

C:\projects\lbdemo\trunk\build.xml [liquibase:updateDatabase] Starting Liquibase.

BUILD FAILED C:\projects\lbdemo\trunk\build.xml:15: Class not found: oracle.jdbc.OracleDriver

Total time: 1 second

How can I tell liquibase in ant where the Oracle Driver sits?

I referred to: http://www.liquibase.org/documentation/ant/index.html

2
You need to include the JDBC driver in the classpath for the Liquibase task (inside the taskdef)a_horse_with_no_name
Thank you, that helped. I included a path tag and referenced it in the updateDatabase tag.Tobias Wittur

2 Answers

0
votes

Here the ant build.xml that ran successfully. The ojdbc driver and liquibase jars are both located in C:\liquibase\; which I reference in the updateDatabase tag: liquibase:updateDatabase classpathref="driver.classpath"

<project name="Example" xmlns:liquibase="antlib:liquibase.integration.ant">

  <path id="driver.classpath"> 
    <filelist dir="C:\liquibase\" > 
      <file name="ojdbc7.jar" /> 
      <file name="liquibase.jar" /> 
    </filelist> 
  </path>

  <property name="db.changelog.file" value="C:\projects\lbdemo\trunk\db_v4.xml"/>
  <property name="database.url" value="jdbc:oracle:thin:@mydb.rds.amazonaws.com:1521:ORCL"/>
  <property name="database.username" value="myuser"/>
  <property name="database.password" value="mypassword"/>
  <property name="database.driver" value="oracle.jdbc.OracleDriver"/>

  <liquibase:database id="my-database" driver="${database.driver}" url="${database.url}" user="${database.username}" password="${database.password}"/>

  <liquibase:updateDatabase classpathref="driver.classpath" databaseref="my-database" changelogfile="${db.changelog.file}"/>

</project>
0
votes

Easier way to do this is to put your all required(liquibase.jar and ojdbc7.jar) libraries into one directory and refer them using path id.

<path id="liquibaseClasspath">
    <fileset dir="C:\projects\lbdemo\trunk\lib" includes="*.jar" />
</path>
<target name="Upgrade_db">
    <echo message="Upgrading DataBase" />
    <updateDatabase changeLogFile="C:\projects\lbdemo\trunk\db_v4.xml" driver="${database.driver}" url="${database.url}" username="${database.username}" password="${database.password}"  classpathref="liquibaseClasspath" />
</target>

You can also mention all the directories location in one file and import that file in your ant file.