liquibase命令行错误org.yaml.snakeyaml.Yaml

时间:2017-10-25 18:21:14

标签: postgresql command-line liquibase

我正在执行以下操作:

liquibase --classpath=./postgresql-42.1.4.jar:./snakeyaml-1.12.jar --changeLogFile=./src/main/resources/db/changelog/db.changelog-master.yaml --username=postgres --password=mysecret --url=jdbc:postgresql://localhost:5432/mydatabase --driver=org.postgresql.Driver update

但我收到了错误

运行Liquibase时出现意外错误:org.yaml.snakeyaml.Yaml

没有其他参考我错误的原因。我怎么知道我使用的蛇形图库是否合适?

编辑: 感谢@bilak我添加了--logLevel = debug flag,但仍然没有多少信息 d

EBUG 10/31/17 4:24 PM: liquibase: Connected to postgres@jdbc:postgresql://localhost:5432/mysdatabase
DEBUG 10/31/17 4:24 PM: liquibase: Setting auto commit to false from true
DEBUG 10/31/17 4:24 PM: liquibase: Executing QUERY database command: select count(*) from public.databasechangeloglock
DEBUG 10/31/17 4:24 PM: liquibase: Executing QUERY database command: select count(*) from public.databasechangeloglock
DEBUG 10/31/17 4:24 PM: liquibase: Executing QUERY database command: SELECT LOCKED FROM public.databasechangeloglock WHERE ID=1
DEBUG 10/31/17 4:24 PM: liquibase: Lock Database
DEBUG 10/31/17 4:24 PM: liquibase: Executing UPDATE database command: UPDATE public.databasechangeloglock SET LOCKED = TRUE, LOCKEDBY = '172.17.0.1 (172.17.0.1)', LOCKGRANTED = '2017-10-31 16:24:07.734' WHERE ID = 1 AND LOCKED = FALSE
INFO 10/31/17 4:24 PM: liquibase: Successfully acquired change log lock
DEBUG 10/31/17 4:24 PM: liquibase: Release Database Lock
DEBUG 10/31/17 4:24 PM: liquibase: Executing UPDATE database command: UPDATE public.databasechangeloglock SET LOCKED = FALSE, LOCKEDBY = NULL, LOCKGRANTED = NULL WHERE ID = 1
INFO 10/31/17 4:24 PM: liquibase: Successfully released change log lock
Unexpected error running Liquibase: org.yaml.snakeyaml.Yaml

SEVERE 10/31/17 4:24 PM: liquibase: org.yaml.snakeyaml.Yaml
java.lang.NoClassDefFoundError: org/yaml/snakeyaml/Yaml
        at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:23)
        at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:229)
        at liquibase.Liquibase.update(Liquibase.java:202)
        at liquibase.Liquibase.update(Liquibase.java:192)
        at liquibase.integration.commandline.Main.doMigration(Main.java:1126)
        at liquibase.integration.commandline.Main.run(Main.java:184)
        at liquibase.integration.commandline.Main.main(Main.java:103)
Caused by: java.lang.ClassNotFoundException: org.yaml.snakeyaml.Yaml
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 7 more

所以它连接并且肯定错误与错误的org.yaml.snakeyaml.Yaml有关我猜  1.类路径没有帮助  2.我试图使用的版本不适合

2 个答案:

答案 0 :(得分:1)

显然需要以某种方式将snakeyaml.jar添加到类路径中 liquibase的--classpath标志和java -cp都不适用于我。我让它运行的最快方法是将驱动程序和yaml jar放在 jre / lib / ext / 中。
这对我来说完全没问题,因为我在Docker容器中运行liquibase

答案 1 :(得分:1)

liquibase 的 --classpath 命令行参数仅用于数据库驱动程序,并不能通过该参数使snakeyaml 可用。

传递给 java 的 -cp 参数确实有效,但需要注意的是,如果您还传递 -jar,它将被忽略。

因此,您需要执行以下操作:

java -cp snakeyaml-1.12.jar:liquibase.jar:sqlite-jdbc-3.34.0.jar liquibase.integration.commandline.Main  --defaultsFile=liquibase.properties --changeLogFile=databaseChangelog.yaml --logLevel debug update