如何设置liquibase类路径

时间:2017-07-16 14:59:04

标签: jhipster liquibase

我创建了一个JHipster项目。我想手动运行liquibase更改集。默认情况下,更改集包含在类路径中。更改日志位于src/main/resources/config/liquibase/master.xml,更改集位于src/main/resources/config/liquibase/changelog

<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd">

    <include file="classpath:config/liquibase/changelog/00000000000000_initial_schema.xml" relativeToChangelogFile="false"/>
    <!-- jhipster-needle-liquibase-add-changelog - JHipster will add liquibase changelogs here -->
    <!-- jhipster-needle-liquibase-add-constraints-changelog - JHipster will add liquibase constraints changelogs here -->
</databaseChangeLog>

运行mvn liquibase:update时,我收到错误,因为即使文件存在,更改集也不在类路径中:

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.3:update (default-cli) on project playground: Error setting up or running Liquibase: liquibase.exception.SetupException: classpath:config/liquibase/changelog/00000000000000_initial_schema.xml does not exist -> [Help 1]

所以我尝试通过设置类路径从命令行运行。

liquibase --classpath=src/main/resources --classpath=postgresql-42.1.3.jar 
--url=jdbc:postgresql://localhost:5432/playground 
--driver=org.postgresql.Driver 
--changeLogFile=src/main/resources/config/liquibase/master.xml 
--username playground --password=***** update

有相同的错误:Unexpected error running Liquibase: classpath:config/liquibase/changelog/00000000000000_initial_schema.xml does not exist

解决方法是删除包含部分中的引用classpath:,但我希望每次使用jhipster entityjhipster import-jdl时jhipster添加更改集时都要避免编辑该文件

2 个答案:

答案 0 :(得分:3)

解决方案是在运行liquibase命令之前运行mvn process-resources,因此src/main/resources下的文件将位于target/classes文件夹中。然后按照https://github.com/jhipster/generator-jhipster/pull/6121

中的说明删除classpath:部分

答案 1 :(得分:1)

好吧...我遇到了同样的问题,因为我不希望jhipster自动更新生产数据库。

因此,从@Sydney建议开始,我决定在 POM 中编写一个新的配置文件,以更改流程资源阶段中的'classpath:'一词,为此,我使用了{{1} }插件,可将ANT文件替换为master.xml。结果是这样的:

<empty>

之后,在命令行中执行以下操作:

<profile> <id>only-liquibase</id> <build> <plugins> <plugin> <groupId>org.liquibase</groupId> <artifactId>liquibase-maven-plugin</artifactId> <version>${liquibase.version}</version> <configuration> <changeLogFile>target/classes/config/liquibase/master.xml</changeLogFile> <driver></driver> <url></url> <defaultSchemaName></defaultSchemaName> <username>dentalaser</username> <password></password> <referenceUrl>hibernate:spring:ec.com.dentalaser.domain?dialect=&amp;hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&amp;hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl> <verbose>true</verbose> <logging>debug</logging> </configuration> <dependencies> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>${javassist.version}</version> </dependency> <dependency> <groupId>org.liquibase.ext</groupId> <artifactId>liquibase-hibernate5</artifactId> <version>${liquibase-hibernate5.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> <version>${project.parent.version}</version> </dependency> <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>${validation-api.version}</version> </dependency> </dependencies> </plugin> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <phase>process-resources</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <echo>Reemplazando el classpath el archivo a desplegar en AWS</echo> <replace file="${project.build.directory}/classes/config/liquibase/master.xml" token="classpath:" value=""/> </target> </configuration> </execution> </executions> </plugin> </plugins> </build> </profile>

或者这个:

./mvnw process-resources liquibase:updateSQL -DskipTests -Dliquibase.url="jdbc:postgresql://<IP>:<PORT>/<DATABASE>" -Dliquibase.password="<supersecret>" -Ponly-liquibase

我真的希望能对您有所帮助!