I try to use Liquibase without any adjacent framework, only by help of Java and I faced with a problem how to run Liquibase. I found an example from official documentation:
java.sql.Connection connection = openConnection(); //your openConnection logic here
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
Liquibase liquibase = new liquibase.Liquibase("path/to/changelog.xml", new ClassLoaderResourceAccessor(), database);
liquibase.update(new Contexts(), new LabelExpression());
but I prefer to use a liquibase.property file with settings located in resources folder. When I used a Spring and Hibernate it works fine, I simply write a properties in application.properties file and that's all, but how to act in this situation?
what about this?
Properties properties = new Properties();
// load properties from classpath
java.sql.Connection connection = openConnection(); //your openConnection logic here
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
try (Liquibase liquibase = new liquibase.Liquibase("path/to/changelog.xml", new ClassLoaderResourceAccessor(), database)){
properties.forEach((key, value) -> liquibase.setChangeLogParameter(Objects.toString(key), value));
liquibase.update(new Contexts(), new LabelExpression());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With