Liquibase:当 changelog.xml 的文件存在时收到 "file does not exist" 异常

Liquibase: receiving "file does not exist" exception when file exists for changelog.xml

我正在尝试实施 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 does not exist

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

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

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

它将搜索到 "UpgradePanDatabase"。class

检查是否 Absolute_path_of_FolderContaing_UpgradePanDatabase.class + /liquibase/db.changelog.xml> 与 IDE.

中的相同

但在你的情况下,应该写入 "classes" 文件夹 尝试调试 - 使用 SOP- "String changelog" 说了什么。这可能会有所帮助。