clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

JDBC Connection fails with "Driver class 'org.slf4j.LoggerFactory' not found."

Open frankwese opened this issue 8 months ago • 7 comments

Describe the bug

In IntelliJ ultimate updated my Clickhouse Datasource from driver version 0.8.2 to 0.8.3 On "Test Connection" the connection fails with this error:

DBMS: ClickHouse (ver. 25.3.2.39) Case sensitivity: plain=exact, delimited=exact Driver: ClickHouse JDBC Driver (ver. 0.6.3 (revision: a6a8a22), JDBC4.2) Driver class 'org.slf4j.LoggerFactory' not found.

Steps to reproduce

  1. update the Driver class to version 0.8.2

frankwese avatar Apr 14 '25 18:04 frankwese

Hi @frankwese - could you please try the shaded-all jar?

We're going to revisit some of the packaging, but in the meanwhile that should resolve this for you.

Paultagoras avatar Apr 15 '25 16:04 Paultagoras

Good day, @frankwese! The problem here is that org.slf4j.LoggerFactory is part of slf4j-api artifact. If we include it as is inside the package it will conflict with application instance of same artifact what is not good because library should have flexible dependencies.
If we include slf4j-api as shaded library it will cause change of FCN of all API classes and it will be hard to use it with other logging backends so logging will be broken for our library.

Solution here may be having several versions of packaging

  • jar with declared dependencies works when application want a full control over dependencies
  • jar + all required dependencies (not shaded) - that would work for your case when application doesn't promote own dependencies
  • jar + some required dependencies (shaded) - that would work for application using different similar client libraries. However there is still a problem with common part libraries like logging, metrics, format processing libraries.

chernser avatar Apr 15 '25 16:04 chernser

@frankwese This worked with shaded-all (rather than just -all) but leaving this open as we (the team) should discuss packaging

Paultagoras avatar Apr 22 '25 06:04 Paultagoras

Just for notes: shaded-all helps to resolve the issue. However 0.8.2-all has the same problem.

Here is application log:

2025-06-03 14:29:20,441 [ 787636]   WARN - #c.i.e.r.RemoteProcessSupport - Remote process stderr:java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

2025-06-03 14:29:20,441 [ 787636]   WARN - #c.i.e.r.RemoteProcessSupport - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
2025-06-03 14:29:20,441 [ 787636]   WARN - #c.i.e.r.RemoteProcessSupport - Remote process stderr:	at com.clickhouse.client.internal.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.<clinit>(PoolingHttpClientConnectionManager.java:108)

2025-06-03 14:29:20,441 [ 787636]   WARN - #c.i.e.r.RemoteProcessSupport - at com.clickhouse.client.internal.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.<clinit>(PoolingHttpClientConnectionManager.java:108)
2025-06-03 14:29:20,441 [ 787636]   WARN - #c.i.e.r.RemoteProcessSupport - Remote process stderr:	at com.clickhouse.client.http.ApacheHttpConnectionImpl.getDefaultUserAgent(ApacheHttpConnectionImpl.java:226)

Adding slf4j-api to the classpath solves the issue:

Image

Why we may not include into -all:

  • This classifier is mainly used by applications that provide own version of slf4j-api and logging backend so we do not want to enforce our version.
  • If we shade slf4j-api then it will be moved to another package and no other logging backend may use it.

chernser avatar Jun 03 '25 21:06 chernser

I'm seeing the same issue when loading the driver into the Splunk DB Connect App as detailed here: https://clickhouse.com/docs/integrations/splunk I was able to load the clickhouse-jdbc-0.8.6-shaded-all.jar release, but I'm afraid of falling behind in future releases as I personally could not find a way to force Splunk's DB Connect App to directly load the slf4j-api JAR file. Maybe somebody knows a way to do this or could share some compilation instructions for folks to include it themselves?

burcheja avatar Jun 24 '25 21:06 burcheja

Good day, @burcheja ! we are planning to create another bundles for such cases that will include everything even such dependencies as API libs.

Do you use on-prem Splunk installation and can you install drivers?

Thanks!

chernser avatar Jun 24 '25 22:06 chernser

Hello @chernser, thanks for the quick response, it's greatly appreciated. That sounds great! I am using an on-premise Splunk installation and can install drivers.

burcheja avatar Jun 24 '25 22:06 burcheja

We have added clickhouse-jdbc-*-all-dependencies.jar to assets of a release. since 0.9.4.

chernser avatar Nov 14 '25 23:11 chernser