Liquibase:当文件存在更改日志时"file does not exist"接收异常.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不存在

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

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

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

它将搜索到"UpgradePanDatabase"。class

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

但在您的情况下,它应该是Wrt到"classes"文件夹试着调试——使用SOP——"字符串变更日志"是怎么说的。这可能会有所帮助。

相关内容

最新更新