org.flywaydb.core.api.FlywayException: 当我的 java class 从 ant taskdef 触发时无法实例化 JDBC 驱动程序
org.flywaydb.core.api.FlywayException: Unable to instantiate JDBC driver when my java class is triggered from ant taskdef
我写了一个 java class 它使用依赖 jar flyway-core-4.0.3.jar 从 taskdef 动作 classpath 加载并调用方法在 flyway jar 中,以下是导致问题的代码部分
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);
}
我正在使用 taskdef 操作通过 ant 触发 class。我已经为 taskdef 操作提供了 classpathref。
<taskdef name="ExecuteMigrationScripts" classname="com.install.common.db.action.ExecuteMigrationScripts"
classpathref="class.dependencies" loaderref="class.dependencies.loader"/>
<ExecuteMigrationScripts/>
仅当 flyway 尝试搜索 db jar 时才会出现此问题(在我的情况下,我已经尝试使用 mysql-connector-java-5.1.39-bin.jar和 sqljdbc41.jar 但同样的问题出现了)。
注意:如果我从尝试连接到数据库并创建示例数据库模式的 taskdef 操作中触发了不同的 class,那么它工作正常并且能够从 classtaskdef 操作中提到的路径,但问题仅在 flyway 尝试定位 db jar 时出现。
如果我在这里遗漏了什么,请帮助我。
有些 flyway 无法获取 jdbc 驱动程序的类路径,即使在调用 taskdef 操作时所有驱动程序 jar 都已添加到类路径中。
但是使用命令 "ant -lib path_to_the_jdbc_driver_jars" 设置类路径解决了我的问题。
我写了一个 java class 它使用依赖 jar flyway-core-4.0.3.jar 从 taskdef 动作 classpath 加载并调用方法在 flyway jar 中,以下是导致问题的代码部分
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);
}
我正在使用 taskdef 操作通过 ant 触发 class。我已经为 taskdef 操作提供了 classpathref。
<taskdef name="ExecuteMigrationScripts" classname="com.install.common.db.action.ExecuteMigrationScripts"
classpathref="class.dependencies" loaderref="class.dependencies.loader"/>
<ExecuteMigrationScripts/>
仅当 flyway 尝试搜索 db jar 时才会出现此问题(在我的情况下,我已经尝试使用 mysql-connector-java-5.1.39-bin.jar和 sqljdbc41.jar 但同样的问题出现了)。
注意:如果我从尝试连接到数据库并创建示例数据库模式的 taskdef 操作中触发了不同的 class,那么它工作正常并且能够从 classtaskdef 操作中提到的路径,但问题仅在 flyway 尝试定位 db jar 时出现。
如果我在这里遗漏了什么,请帮助我。
有些 flyway 无法获取 jdbc 驱动程序的类路径,即使在调用 taskdef 操作时所有驱动程序 jar 都已添加到类路径中。
但是使用命令 "ant -lib path_to_the_jdbc_driver_jars" 设置类路径解决了我的问题。