How to do update with include tag through liquibase command line with war as classpath

1k Views Asked by At

What am I trying to do

I'm trying to run an update on a MySQL database using Liquibase's command line tool and a .war file, and it's important to not touch the master.xml file unless I absolutely have to as to not break the project run with maven and Jhipster.

What does my code look like

Following the official documentations's example of how to set up the path:

java -jar liquibase.jar \
      --driver=oracle.jdbc.OracleDriver \
      --classpath=website.war \
      --changeLogFile=com/example/db.changelog.xml \
      --url=jdbc:oracle:thin:@localhost:1521:oracle \
      --username=scott \
      --password=tiger \
      update

I made my liquibase.properties as following:

url=jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=utf8&useSSL=false&createDatabaseIfNotExist=true
username=username
password=password
driver=com.mysql.jdbc.Driver
classpath=target/application-0.0.1-SNAPSHOT.war
changeLogFile=src/main/resources/config/liquibase/master.xml

My master.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

    <include file="classpath:config/liquibase/changelog/00000000000000_initial_schema.xml" relativeToChangelogFile="false"/>
</databaseChangeLog>

And my commandline command looks like this:

liquibase --defaultsFile=../dev.properties update

What's the error

When I run this I get the following error:

Unexpected error running Liquibase: java.lang.IllegalArgumentException: name

And of course nothing happens. Liquibase runs it's startup just fine so there's the DATABASECHANGELOGLOCK table in the database.

What I've tried

I've tried editing my changeLogFile property to the following:

changeLogFile=/home/user/project_src/src/main/resources/config/liquibase/master.xml
changeLogFile=WEB-INF/classes/config/liquibase/master.xml

However, these return the same error message. If I try to use the exact path on my system to the changefile I, of course get this:

Unexpected error running Liquibase: /home/user/project_src/~/project_src/src/main/resources does not exist

SEVERE 5/19/17 9:38 AM: liquibase: /home/user/project_src/~/project_src/src/main/resources does not exist
liquibase.exception.CommandLineParsingException: /home/user/project_src/~/project_src/src/main/resources does not exist
    at liquibase.integration.commandline.Main.configureClassLoader(Main.java:828)
    at liquibase.integration.commandline.Main.run(Main.java:187)
    at liquibase.integration.commandline.Main.main(Main.java:103)

I've also tried to edit the master.xml to make the include tag look like this:

<include file="changelog/00000000000000_initial_schema.xml" relativeToChangelogFile="true"/>

This does work for the command line tool, but since this is also run through maven and Jhipster I'd rather not manipulate this file unless I have to.

All the mentioned technologies are the latest stable versions from their dists and I've had this issue on Ubuntu 16.10 and 17.04.

A workaround I've gotten to work

If I put a changefile path directly instead of the master.xml it runs beautifully with any of the above listed versions of the path, but then I'd have to run each change log manually completely losing the point of the master.xml and its include tag.

Other information

The project was generated using Jhipster.

0

There are 0 best solutions below