简体   繁体   中英

No suitable driver found for sqlite in a runtime image java

I'm working on a Maven JavaFX project with sqlite and my goal is to create an installer using jpackage. One of the first steps is to create a runtime image. So I was planning on creating the image, make sure that it runs and then create an installer using jpackage.

These are my dependencies in Maven:

org.openjfx javafx-controls 14 org.openjfx javafx-fxml 14 org.xerial sqlite-jdbc 3.30.1 jar

This is how I connect to the db:

connection=(Connection) DriverManager.getConnection("jdbc:sqlite:"+getClass().getResource("database.db"));

I create the runtime image with maven:

mvn clean javafx:jlink

And when I run the image I get the following error:

java.sql.SQLException: No suitable driver found for jdbc:sqlite:

I tried adding Class.forName("org.sqlite.JDBC"); but now I'm getting:

java.lang.ClassNotFoundException: org.sqlite.jdbc

I already tried following these instructions but I keep getting the same errors.

Everything works fine when I run the project using InteliJ. I've been trying to get this to work for a while now and I keep failing. Does anyone know what I'm doing wrong or what I need to add or change?

I have SQLite running without problems. For building I follow this tutorial https://github.com/dlemmermann/JPackageScriptFX which I created together with Dirk Lemmermann. There isn't anything special to do for SQLite. If you want to use it via the Maven shade plugin or the GraalVM things get a little bit more complicated but it also works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM