Mad Scientist
Mad Scientist

Reputation: 917

Cant run liquibase with command line

I want to use liquibase but when I want to let it run with command line this happens:

PS C:\Users\Ferid\Downloads\liquibase-3.6.0-bin> .\liquibase
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: ch/qos/logback/core/filter/Filter
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.privateGetMethodRecursive(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
 Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.filter.Filter
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 7 more

I have tried liquibase-3.6.1 and now liquibase-3.6.0

Upvotes: 21

Views: 14569

Answers (3)

raiks
raiks

Reputation: 1520

I stumbled upon the same issue in version 3.6.2. The problem is that Liquibase can't find the required classes (ch.qos.logback.core.filter.Filter being just one of them, but there are others). There is no universal recipe, but the high-level idea is to found JARs the required classes live in and feed them to the -cp command-line parameter. Looks a bit ugly but this is what finally worked:

#!/bin/bash

M2_REPO=/home/raiks/.m2/repository
LIQUIBASE_CMDLINE='liquibase.integration.commandline.Main --changeLogFile=~/changelog-master.xml update'
# Feed all the required JARs to -cp
JAVA_CMD="java -cp $M2_REPO/org/liquibase/liquibase-core/3.6.2/liquibase-core-3.6.2.jar:$M2_REPO/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar:$M2_REPO/ch/qos/logback/logback-core/1.2.3/logback-core-1.2.3.jar:$M2_REPO/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar $LIQUIBASE_CMDLINE"
echo $JAVA_CMD
eval $JAVA_CMD

Please note that I use : on Linux while ; will be required on Windows. Adjust the command according to your specific JAR location.

Alternatively, you can put dependencies to a directory and specify it with a wildcard after -cp:

   $ java -cp "/home/raiks/liquibase-deps/*" liquibase.integration.commandline.Main --changeLogFile=~/changelog-master.xml update

Upvotes: 3

Alan Hernandez
Alan Hernandez

Reputation: 339

You must add this libraries to your classpath:

In my case I am using Spring Boot liquibase integration, so, here is my build.gradle liquibase configutarion

buildscript {
    dependencies {
        classpath 'org.postgresql:postgresql:9.4.1211.jre7'
        classpath 'org.liquibase:liquibase-core:3.6.3'
        classpath "org.liquibase:liquibase-gradle-plugin:2.0.1"
    }
}

plugins {
    id 'org.springframework.boot' version '2.1.3.RELEASE'
    id 'java'
    id "org.liquibase.gradle" version "2.0.1"
}


dependencies {
    liquibaseRuntime 'org.postgresql:postgresql:9.4.1211.jre7'
    liquibaseRuntime 'org.liquibase:liquibase-core:3.6.3'
    liquibaseRuntime 'org.liquibase:liquibase-groovy-dsl:2.0.1'
    liquibaseRuntime 'ch.qos.logback:logback-core:1.2.3'
    liquibaseRuntime 'ch.qos.logback:logback-classic:1.2.3'
}

def changeLog = "$projectDir/src/main/db/changelog.xml"
liquibase {
    activities {
        main {
            changeLogFile changeLog
            url 'jdbc:postgresql://localhost:5431/postgres'
            username 'postgres'
            password 'postgres'
        }
    }
}

It's an extract from liquibase-gradle-plugin

Upvotes: 5

sorifiend
sorifiend

Reputation: 6307

One of the required libraries is missing from the library folder.

See the bug report link below where another user had the same issue.

It appears 3.6.1 is still missing slf4j-api-1.7.25 in the lib folder and I still receive an error invoking liquibase via cli.

You have three options:

  1. Get the library yourself [here].
  2. Wait for the patched version (Maybe submit a fix yourself).
  3. Revert to an older version (3.5.5 Should work)

See here for the bug report: https://liquibase.jira.com/browse/CORE-3201

Upvotes: 28

Related Questions