带有Gradle自定义运行时映像的java SQLite JDBC
我已经在build.gradle
中添加了SQLite,并尝试使用Gradle4.10中的org.beryx.jlink
插件创建自定义运行时映像。当我运行映像时,我收到错误:No suitable driver found for jdbc:sqlite:
This question和this one处理一个类似的问题,但不是具体到运行时映像
我在构建中添加了SQLite。格拉德尔:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.7'
id 'org.beryx.jlink' version '2.9.4'
}
repositories {
mavenCentral()
}
javafx {
version = "12"
modules = [ 'javafx.controls', 'javafx.fxml']
}
dependencies {
compile 'org.xerial:sqlite-jdbc:3.20.1'
}
jlink {
launcher {
name = 'bankstatementprocessor'
}
}
一旦我想在代码中连接到SQLite DB,就会出现错误No suitable driver found for jdbc:sqlite:
conn = DriverManager.getConnection(CONNECTION_STRING);
作为验证,我包括以下内容:
Class.forName("org.sqlite.JDBC");
并且,我收到了错误:java.lang.ClassNotFoundException: org.sqlite.JDBC
Maven似乎有办法解决这个问题,如图here:
当我简单地使用./gradlew run
运行项目时没有错误;但是,该映像似乎没有注册SQLite驱动程序
# 1 楼答案
实现预期结果的一种可能方法是pick your JDBC driver at runtime。我并不特别喜欢这种方法,因为我觉得在
build.gradle
文件中应该有一种更干净的方法