【问题标题】:Liquibase: receiving "file does not exist" exception when file exists for changelog.xmlLiquibase:当 changelog.xml 的文件存在时收到“文件不存在”异常
【发布时间】:2023-03-31 20:21:01
【问题描述】:

我正在尝试实现 java 触发的 liquibase 数据库更新。

我有以下代码:

java.sql.Connection connection = openConnection(eventContext); 
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
String changelog = UpgradePanDatabase.class.getResource("/liquibase/db.changelog.xml").getPath();
Liquibase liquibase = new liquibase.Liquibase(changelog, new ClassLoaderResourceAccessor(), database);
liquibase.update(new Contexts(), new LabelExpression());
connection.close();

但我收到以下 ChangeLogParseException:

/Users/ntregillus/myApp/.mule/apps/myApp/classes/liquibase/db.changelog.xml 不存在

但我知道文件存在,我可以复制路径,直接从终端打开它,也可以在文件资源管理器中找到它。为什么 Liquibase 找不到这个文件?

【问题讨论】:

  • 为了全面披露,我正在部署的 mule 组件中运行此代码

标签: java mule liquibase


【解决方案1】:

最可能的原因是更改日志没有被打包为 jar 文件中的资源。检查打包 jar 的结构而不是本地开发人员的工作副本。

【讨论】:

  • 就是这样。该文件未包含在 jar 中
【解决方案2】:

UpgradePanDatabase.class.getResource("/liquibase/db.changelog.xml")

它将搜索到“UpgradePanDatabase”.class

检查是否 Absolute_path_of_FolderContaing_UpgradePanDatabase.class + /liquibase/db.changelog.xml> 与您的 IDE 中的相同。

但在你的情况下,它应该是 Wrt 到“类”文件夹 尝试调试-使用 SOP-“字符串更改日志”说什么。这可能会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-21
    • 2013-01-23
    • 2019-08-25
    • 2016-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多