How would one start a liquibase schema db check aginst a base line under Tomcat on a schedule? Like how to deploy liquibase under Tomcat?
Asked
Active
Viewed 434 times
1 Answers
1
What about utilizing ServletContextListener
and inside it create new object of
Liquibase.
something like
import java.sql.Connection;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import liquibase.Liquibase;
import liquibase.database.Database;
import liquibase.database.DatabaseFactory;
import liquibase.database.jvm.JdbcConnection;
import liquibase.resource.ClassLoaderResourceAccessor;
import liquibase.resource.CompositeResourceAccessor;
import liquibase.resource.FileSystemResourceAccessor;
import lombok.SneakyThrows;
@WebListener
public class LiquibaseListener implements ServletContextListener {
@SneakyThrows
@Override
public void contextInitialized(ServletContextEvent sce) {
final Connection connection = null;
final Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
final Liquibase liquibase = new Liquibase("changelogpath", new CompositeResourceAccessor(new ClassLoaderResourceAccessor(), new FileSystemResourceAccessor()), database);
liquibase.update("");
}
}
Or have a look inside SpringLiquibase how this is done for spring framework and you can get inspiration from there.

bilak
- 4,526
- 3
- 35
- 75
-
Thanks for the info @bilak In your code, how would i tell it I want JSON output for the results? – StealthRT Sep 24 '20 at 18:01
-
for which results? – bilak Sep 24 '20 at 18:56
-
I thought there was only one output and that was to display each checked database table and determine if its the same or to list what was not the same. – StealthRT Sep 24 '20 at 18:59