sqlite-jdbc icon indicating copy to clipboard operation
sqlite-jdbc copied to clipboard

tomcat + spring boot : No suitable driver found

Open guiguilechat opened this issue 8 months ago • 10 comments
trafficstars

Describe the bug tomcat + spring boot Caused by: java.sql.SQLException: No suitable driver found for jdbc:sqlite::memory:

To Reproduce

TLDR : clone my minimal project https://github.com/guiguilechat/xerial-sqlite-testtomcat and run the sh/test script


I created a spring boot app, that is built with maven-war-plugin (package phase, war type), and has the


		<dependency>
			<groupId>org.xerial</groupId>
			<artifactId>sqlite-jdbc</artifactId>
		</dependency>

(managed in root pom, v3.49.1.0)

I can run it locally with an main() calling SpringApplication.run In that case it can open a connection to a new inmemory db no problem (which I use to load downloaded sqlite file and integrate the data).

However when I scp the war to the tomcat directory , the tomcat app complains

Caused by: java.sql.SQLException: No suitable driver found for jdbc:sqlite::memory: at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:708) ~[java.sql:na] at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:253) ~[java.sql:na]

Environment (please complete the following information):

  • OS: [Ubuntu 24.04.2 LTS]
  • sqlite-jdbc 3.49.1.0

Additional context

I know of https://github.com/xerial/sqlite-jdbc/issues/145#issuecomment-330110661 I tried this (by copying the plugin conf from https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-parent/3.4.3/spring-boot-starter-parent-3.4.3.pom and adding the execution on package) but it did not work(same issue).

It's weird because the app runs against a postgresql instance (in the same server) and can find it no problem. I also added the oracle driver and was able to dockerize it against a oracle docker image.

Also when I look in the packaged war, there is no META-INF/services/java.sql.Driver ; only maven/ and MANIFEST.MF

guiguilechat avatar Mar 13 '25 18:03 guiguilechat

did you check https://github.com/xerial/sqlite-jdbc?tab=readme-ov-file#hint-for-maven-shade-plugin ?

gotson avatar Mar 14 '25 01:03 gotson

@gotson Yes this is explained in the additional context.

guiguilechat avatar Mar 14 '25 09:03 guiguilechat

added a minimal-ish maven project to test. Uses docker to start a tomcat image

https://github.com/guiguilechat/xerial-sqlite-testtomcat

sh/test script does all.

Result for me :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2025-04-17T16:17:04.081Z ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadDB' defined in file [/usr/local/tomcat/webapps/TestXerialSqliteTomcat/WEB-INF/classes/fr/guiguilechat/tests/xerial/LoadDB.class]: No suitable driver found for jdbc:sqlite::memory:

While when running in Eclipse IDE : INFO 191800 --- [ main] fr.guiguilechat.tests.xerial.LoadDB : succesfuly loaded db

guiguilechat avatar Apr 17 '25 16:04 guiguilechat

tried with tomcat image 11.0.6 and same issue.

guiguilechat avatar Apr 17 '25 16:04 guiguilechat

forced the last version of xerials (dependency management) and added maven-shade transformer, no difference.

guiguilechat avatar Apr 17 '25 16:04 guiguilechat

Your project is ill-designed. Why are you using Maven Shade Plugin with the Spring Boot Maven Plugin? Both do repackage the target artifact. Since the Spring Boot Maven Plugin creates a fat JAR, I guess the FS layout along with the extraction code does not work. You will need to put this driver onto the system class loader like the booter JAR.

michael-o avatar Jun 01 '25 19:06 michael-o

Your project is ill-designed. Why are you using Maven Shade Plugin with the Spring Boot Maven Plugin? Both do repackage the target artifact. Since the Spring Boot Maven Plugin creates a fat JAR, I guess the FS layout along with the extraction code does not work. You will need to put this driver onto the system class loader like the booter JAR.

Why ? Because people mentioned it in that post.

I tried WITHOUT shade plugin and this changed nothing. WTF are you nitpicking while you could instead shut the fuck up ? This is literally written on the post above yours FFS. With corresponding commit : https://github.com/guiguilechat/xerial-sqlite-testtomcat/commit/40720379dc0d945aa624aef2c1621ac9d556124a

You are not helping.

guiguilechat avatar Jun 02 '25 11:06 guiguilechat

Your project is ill-designed. Why are you using Maven Shade Plugin with the Spring Boot Maven Plugin? Both do repackage the target artifact. Since the Spring Boot Maven Plugin creates a fat JAR, I guess the FS layout along with the extraction code does not work. You will need to put this driver onto the system class loader like the booter JAR.

Why ? Because people mentioned it in that post.

I tried WITHOUT shade plugin and this changed nothing. WTF are you nitpicking while you could instead shut the fuck up ? This is literally written on the post above yours FFS. With corresponding commit : guiguilechat/xerial-sqlite-testtomcat@4072037

You are not helping.

The Spring Boot plugin is still in place.

michael-o avatar Jun 02 '25 12:06 michael-o

@michael-o
Did you try it without it ?

guiguilechat avatar Jun 02 '25 14:06 guiguilechat

@michael-o Did you try it without it ?

image

michael-o avatar Jun 02 '25 14:06 michael-o