I have written a java class which uses the dependency jar flyway-core-4.0.3.jar loaded from the taskdef action classpath and invoking the methods in the flyway jar, the following is the part of the code which is causing the issue
public static boolean executeFlywayMigrate(String connectionUrl, String username, String password,
String scriptLocation, String[] databaseNames, Map<String, String> componentProperties,
boolean validateOnMigrate)
throws SQLException {
LOGGER.info("Database schemas for migration are :" + Arrays.toString(databaseNames));
try {
Flyway flyway = new Flyway();
flyway.setLocations(scriptLocation);
flyway.setSchemas(databaseNames);
flyway.setBaselineOnMigrate(true);
flyway.setDataSource(connectionUrl, username, password);
if (componentProperties != null) {
flyway.setPlaceholders(componentProperties);
}
flyway.setValidateOnMigrate(validateOnMigrate);
flyway.repair();
flyway.migrate();
} catch (RuntimeException e) {
LOGGER.error("Database migration failed.", e);
throw new SQLException(e);
}
I am triggering the class with ant using taskdef action. I have given the classpathref for the taskdef action.
<taskdef name="ExecuteMigrationScripts" classname="com.install.common.db.action.ExecuteMigrationScripts"
classpathref="class.dependencies" loaderref="class.dependencies.loader"/>
<ExecuteMigrationScripts/>
The issue occurs only when flyway tries to seach for the db jar (in my case i have tried with both mysql-connector-java-5.1.39-bin.jar and sqljdbc41.jar but the same issue arises).
NOTE: If i trigger a different class from taskdef action which tries to connect to the database and create a sample database schema, that works fine and that could able to load the same db jars from the classpath mentioned in the taskdef action but the issue occurs only when flyway is trying to locate the db jar.
Please help me if i am missing something here.