【问题标题】:Liquibase Changesets within JAR filesJAR 文件中的 Liquibase 变更集
【发布时间】:2015-08-23 20:58:45
【问题描述】:

目前我尝试将 Liquibase 3.3.3 集成到我的项目中。为了管理我的数据库,我从我的应用程序中调用 Liquibase,而变更集位于一个 JAR 文件中,其中

final Liquibase liquibase = new Liquibase( "db/db_changelog_master.xml",
                                           new ClassLoaderResourceAccessor(),
                                           database );
liquibase.update( new Contexts() );

此调用有效,主变更集已加载。在主变更集中加载更多变更集:

<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                                       http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
                                       http://www.liquibase.org/xml/ns/dbchangelog-ext
                                       http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
    <include file="classpath:db_changelog_1.0.xml"/>
</databaseChangeLog>

问题从这里开始,因为 Liquibase 无法找到并加载子变更集。我还尝试了 标记以及子变更集的绝对和相对路径,但没有成功。

有什么建议吗?

最好的问候!

【问题讨论】:

  • 也许您应该添加更改日志文件的文件夹结构。 db_changelog_1.0.xml 是否也在 db 文件夹中?你试过/db/db_changelog_1.0.xml/db_changelog_1.0.xmldb/db_changelog_1.0.xml吗?
  • 您找到解决方案了吗?

标签: java liquibase changeset


【解决方案1】:

我在 src/main/resources/db/changelog/dbchange-master.xml 和 dbchange-2.xml 的其他 jar 中有我的更改日志

如果我像这样在 master 中包含 dbchange-2.xml

<include file="classpath:/db/changelog/dbchange-2.xml" />

它有效。

【讨论】:

    【解决方案2】:

    在 jar 中分发 changesets 并通过 classpath 加载它们的关键是在您的根 changelog 中添加 classpath 架构后缀*,因此是&lt;includeAll path="classpath*:/db/changelog/changesets"/&gt;

    注意:这在Liquibase 的某些版本中被破坏了。

    <databaseChangeLog  
                    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"  
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
                    xmlns:pro="http://www.liquibase.org/xml/ns/pro"  
                    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
                        http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.8.xsd">
      
      <includeAll path="classpath*:/db/changelog/changesets"/>
    
    </databaseChangeLog>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-01
      • 1970-01-01
      • 2012-08-12
      • 2021-11-16
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      • 2015-08-01
      相关资源
      最近更新 更多