This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch CAMEL-27447-jbang-debezium-jdbc-drivers
in repository https://gitbox.apache.org/repos/asf/camel.git

commit bf149118b5f000afe4a11d172cab395d386f62fd
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 23 12:26:22 2026 +0100

    CAMEL-27447: camel-jbang - download the JDBC driver of debezium-mysql and 
debezium-db2
    
    A debezium-mysql route failed to start on the Camel CLI with
    ClassNotFoundException: com.mysql.cj.jdbc.Driver. The MySQL driver is GPL
    licensed, so camel-debezium-mysql declares it provided, and Debezium loads
    it with Class.forName on the class loader of its connector, which does not
    go through the class resolver that downloads the known third-party
    libraries (as it does for a sql or jdbc route). The Debezium Db2 connector
    has the same problem: its driver com.ibm.db2:jcc (IBM IPLA license) is a
    provided dependency of Debezium. The Oracle, SQL Server, PostgreSQL and
    MongoDB connectors depend on their driver, so it comes with the component.
    
    The component resolver of camel-kamelet-main already resolved the pooled-jms
    class for activemq through the class resolver. That is now a small table of
    component name to needed class, with debezium-mysql 
(com.mysql.cj.jdbc.Driver)
    and debezium-db2 (com.ibm.db2.jcc.DB2Driver). Resolving the class downloads
    the library from known-third-party-libraries.properties in the version Camel
    manages, and the download is recorded, so camel export adds it to the
    exported project too. Camel itself still does not depend on either driver.
    
    The Db2 driver is mapped by package with a new debezium-db2-jcc-version
    property in camel-parent.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../camel/catalog/docs/debezium-db2-component.adoc | 17 +++++++
 .../catalog/docs/debezium-mysql-component.adoc     |  3 ++
 .../src/main/docs/debezium-db2-component.adoc      | 17 +++++++
 .../src/main/docs/debezium-mysql-component.adoc    |  3 ++
 .../modules/ROOT/pages/camel-jbang-running.adoc    | 12 +++++
 .../DependencyDownloaderComponentResolver.java     | 26 ++++++++--
 .../main/known-third-party-libraries.properties    |  1 +
 .../DependencyDownloaderComponentResolverTest.java | 55 +++++++++++++++++++++-
 parent/pom.xml                                     |  1 +
 9 files changed, 131 insertions(+), 4 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
index bbb52dab3932..78e2270de54d 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-db2-component.adoc
@@ -59,6 +59,23 @@ for this component.
 debezium-db2:name[?options]
 ----
 
+[NOTE]
+====
+The JDBC driver of Db2 is not included, as its license is not the Apache 
license. Add the dependency for
+`com.ibm.db2:jcc` to your POM file:
+
+[source,xml]
+----
+<dependency>
+    <groupId>com.ibm.db2</groupId>
+    <artifactId>jcc</artifactId>
+    <version>x.x.x</version>
+</dependency>
+----
+
+The Camel CLI downloads the driver by itself when a route uses this component, 
and `camel export` adds it to the
+exported project.
+====
 
 // component options: START
 include::partial$component-configure-options.adoc[]
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
index 8f3db6306db0..07077e1662d3 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/debezium-mysql-component.adoc
@@ -69,6 +69,9 @@ Due to licensing issues, you will need to add the dependency 
for `mysql-connecto
     <version>8.0.15</version>
 </dependency>
 ----
+
+The Camel CLI downloads the driver by itself when a route uses this component, 
and `camel export` adds it to the
+exported project.
 ====
 
 // component options: START
diff --git 
a/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
 
b/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
index bbb52dab3932..78e2270de54d 100644
--- 
a/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
+++ 
b/components/camel-debezium/camel-debezium-db2/src/main/docs/debezium-db2-component.adoc
@@ -59,6 +59,23 @@ for this component.
 debezium-db2:name[?options]
 ----
 
+[NOTE]
+====
+The JDBC driver of Db2 is not included, as its license is not the Apache 
license. Add the dependency for
+`com.ibm.db2:jcc` to your POM file:
+
+[source,xml]
+----
+<dependency>
+    <groupId>com.ibm.db2</groupId>
+    <artifactId>jcc</artifactId>
+    <version>x.x.x</version>
+</dependency>
+----
+
+The Camel CLI downloads the driver by itself when a route uses this component, 
and `camel export` adds it to the
+exported project.
+====
 
 // component options: START
 include::partial$component-configure-options.adoc[]
diff --git 
a/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
 
b/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
index 8f3db6306db0..07077e1662d3 100644
--- 
a/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
+++ 
b/components/camel-debezium/camel-debezium-mysql/src/main/docs/debezium-mysql-component.adoc
@@ -69,6 +69,9 @@ Due to licensing issues, you will need to add the dependency 
for `mysql-connecto
     <version>8.0.15</version>
 </dependency>
 ----
+
+The Camel CLI downloads the driver by itself when a route uses this component, 
and `camel export` adds it to the
+exported project.
 ====
 
 // component options: START
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-running.adoc 
b/docs/user-manual/modules/ROOT/pages/camel-jbang-running.adoc
index 6ad17c4119fb..44590d3d2434 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-running.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-running.adoc
@@ -435,6 +435,18 @@ headers of the `aws-s3-source` Kamelet gets 
`camel-aws2-s3` before the route is
 that is only looked up while running still needs the component class itself, 
so probing whether
 a class is present does not download a component.
 
+A few components need a library that is not one of their dependencies and load 
its classes without
+asking Camel, so no lookup would happen. Camel CLI looks up a class of the 
library when a route uses
+the component, which downloads the library in the version Camel manages, and 
`camel export` adds it
+to the exported project:
+
+* `activemq` and `activemq6`: the JMS connection pool 
`org.messaginghub:pooled-jms`.
+* `debezium-mysql`: the MySQL JDBC driver `com.mysql:mysql-connector-j`, which 
is under the GPL.
+* `debezium-db2`: the Db2 JDBC driver `com.ibm.db2:jcc`, which is under the 
IBM International
+  Program License Agreement.
+
+The other Debezium components come with the JDBC driver of their database.
+
 A dependency you declare yourself, with `--dep`, `camel.jbang.dependencies`, 
or in the project's
 POM, is on the classpath before any lookup, so it always takes precedence. Use 
that when a
 mapped library is not the one you want, for example the ActiveMQ 5 client 
where the mapping
diff --git 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
index 9fd8e709ced8..cf46a230b323 100644
--- 
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
+++ 
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderComponentResolver.java
@@ -18,6 +18,7 @@ package org.apache.camel.main.download;
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
@@ -44,6 +45,24 @@ public final class DependencyDownloaderComponentResolver 
extends DefaultComponen
             "stub", "direct", "log", "seda"
     };
 
+    /**
+     * A class that a component needs, from a library that is not a dependency 
of the component, by component name. The
+     * class is resolved through the class resolver when the component is 
resolved, which downloads its library from the
+     * third-party known dependencies (known-third-party-libraries.properties) 
in the version Camel manages. As the
+     * download is recorded, camel export adds the library to the exported 
project too.
+     * <p/>
+     * The JDBC drivers of the Debezium connectors that their license keeps 
out of the component are here (CAMEL-27447):
+     * Debezium loads the driver itself with Class.forName, which does not go 
through the class resolver.
+     */
+    private static final Map<String, String> NEEDED_CLASSES = Map.of(
+            // the JMS connection pool
+            "activemq", "org.messaginghub.pooled.jms.JmsPoolConnectionFactory",
+            "activemq6", 
"org.messaginghub.pooled.jms.JmsPoolConnectionFactory",
+            // the MySQL JDBC driver is GPL licensed
+            "debezium-mysql", "com.mysql.cj.jdbc.Driver",
+            // the Db2 JDBC driver is under the IBM International Program 
License Agreement
+            "debezium-db2", "com.ibm.db2.jcc.DB2Driver");
+
     private final CamelCatalog catalog = new DefaultCamelCatalog();
     private final CamelContext camelContext;
     private final DependencyDownloader downloader;
@@ -117,10 +136,11 @@ public final class DependencyDownloaderComponentResolver 
extends DefaultComponen
                 downloader.downloadDependency("org.hibernate.orm", 
"hibernate-core", "${hibernate-version}");
             }
         }
-        if ("activemq".equals(name) || "activemq6".equals(name)) {
-            // need to include JMS connection-pool (trigger class loader to 
download correct JAR)
+        String neededClass = NEEDED_CLASSES.get(name);
+        if (neededClass != null) {
+            // trigger the class loader to download the JAR of the class 
(known-third-party-libraries.properties)
             try {
-                
camelContext.getClassResolver().resolveClass("org.messaginghub.pooled.jms.JmsPoolConnectionFactory");
+                camelContext.getClassResolver().resolveClass(neededClass);
             } catch (Exception e) {
                 // ignore
             }
diff --git 
a/dsl/camel-kamelet-main/src/main/known-third-party-libraries.properties 
b/dsl/camel-kamelet-main/src/main/known-third-party-libraries.properties
index 72f6b87c9276..0410bf96e4d2 100644
--- a/dsl/camel-kamelet-main/src/main/known-third-party-libraries.properties
+++ b/dsl/camel-kamelet-main/src/main/known-third-party-libraries.properties
@@ -33,6 +33,7 @@
 # JDBC drivers, datasources and connection pools
 org.postgresql = org.postgresql:postgresql:${pgjdbc-driver-version}
 com.mysql.cj = com.mysql:mysql-connector-j:${debezium-mysql-connector-version}
+com.ibm.db2.jcc = com.ibm.db2:jcc:${debezium-db2-jcc-version}
 org.mariadb.jdbc = org.mariadb.jdbc:mariadb-java-client:${mariadb-version}
 com.microsoft.sqlserver.jdbc = 
com.microsoft.sqlserver:mssql-jdbc:${mssql-jdbc-version}
 oracle.jdbc = com.oracle.database.jdbc:ojdbc17:${ojdbc-version}
diff --git 
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
 
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
index 3c418c39a81c..30d1ff4cd562 100644
--- 
a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
+++ 
b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/download/DependencyDownloaderComponentResolverTest.java
@@ -24,6 +24,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.junit.jupiter.api.Test;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -46,14 +47,63 @@ class DependencyDownloaderComponentResolverTest {
         assertTrue(downloaded.contains("camel-http"), downloaded.toString());
     }
 
+    @Test
+    void theDebeziumMySqlConnectorDownloadsTheMySqlDriver() throws Exception {
+        // CAMEL-27447: the MySQL driver is GPL licensed and not a dependency 
of camel-debezium-mysql, and Debezium
+        // loads it with Class.forName, which does not go through the class 
resolver that downloads it
+        List<String> downloaded = download("debezium-mysql");
+        assertDownloaded(downloaded, "org.apache.camel:camel-debezium-mysql");
+        assertDownloaded(downloaded, "com.mysql:mysql-connector-j");
+    }
+
+    @Test
+    void theDebeziumDb2ConnectorDownloadsTheDb2Driver() throws Exception {
+        // CAMEL-27447: the Db2 driver is a provided dependency of the 
Debezium Db2 connector
+        List<String> downloaded = download("debezium-db2");
+        assertDownloaded(downloaded, "org.apache.camel:camel-debezium-db2");
+        assertDownloaded(downloaded, "com.ibm.db2:jcc");
+    }
+
+    @Test
+    void theOtherDebeziumConnectorsComeWithTheirDriver() throws Exception {
+        // the Debezium connector depends on the driver, so it is a dependency 
of the component
+        for (String component : List.of("debezium-postgres", 
"debezium-sqlserver", "debezium-oracle", "debezium-mongodb")) {
+            List<String> downloaded = download(component);
+            assertEquals(1, downloaded.size(), downloaded.toString());
+            assertDownloaded(downloaded, "org.apache.camel:camel-" + 
component);
+        }
+    }
+
+    @Test
+    void activeMqDownloadsTheJmsConnectionPool() throws Exception {
+        List<String> downloaded = download("activemq");
+        assertDownloaded(downloaded, "org.messaginghub:pooled-jms");
+    }
+
+    /** The dependency is asked once, with a version (the third-party versions 
are resolved at build time). */
+    private static void assertDownloaded(List<String> downloaded, String 
groupIdArtifactId) {
+        List<String> found = downloaded.stream().filter(gav -> 
gav.startsWith(groupIdArtifactId + ":")).toList();
+        assertEquals(1, found.size(), downloaded.toString());
+        String version = found.get(0).substring(groupIdArtifactId.length() + 
1);
+        assertTrue(!version.isBlank() && !"null".equals(version) && 
!version.contains("${"), found.get(0));
+    }
+
     /** The artifacts the resolver asks to download for the component, with 
nothing on the classpath. */
     private static List<String> resolve(String component) throws Exception {
+        return download(component).stream().map(gav -> 
gav.split(":")[1]).toList();
+    }
+
+    /**
+     * The groupId:artifactId:version the resolver asks to download for the 
component, with nothing on the classpath and
+     * the class resolver of Camel CLI, which downloads the known third-party 
libraries.
+     */
+    private static List<String> download(String component) throws Exception {
         List<String> downloaded = new ArrayList<>();
         DependencyDownloader downloader = (DependencyDownloader) 
Proxy.newProxyInstance(
                 
DependencyDownloaderComponentResolverTest.class.getClassLoader(),
                 new Class<?>[] { DependencyDownloader.class }, (proxy, method, 
args) -> switch (method.getName()) {
                     case "downloadDependency" -> {
-                        downloaded.add((String) args[1]);
+                        downloaded.add(args[0] + ":" + args[1] + ":" + 
args[2]);
                         yield null;
                     }
                     case "hashCode" -> System.identityHashCode(proxy);
@@ -63,6 +113,9 @@ class DependencyDownloaderComponentResolverTest {
                 });
         try (CamelContext context = new DefaultCamelContext()) {
             context.addService(downloader);
+            KnownDependenciesResolver known = new 
KnownDependenciesResolver(context, null, null);
+            known.loadKnownDependencies();
+            context.setClassResolver(new 
DependencyDownloaderClassResolver(context, known, false));
             DependencyDownloaderComponentResolver resolver
                     = new DependencyDownloaderComponentResolver(context, null, 
false, false);
             try {
diff --git a/parent/pom.xml b/parent/pom.xml
index 68b82066b9bc..069af15de9ca 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -157,6 +157,7 @@
         <dapr-workflow-version>1.19.0</dapr-workflow-version>
         <datasonnet-mapper-version>3.0.1.3</datasonnet-mapper-version>
         <debezium-version>3.7.1.Final</debezium-version>
+        <debezium-db2-jcc-version>12.1.5.0</debezium-db2-jcc-version>
         
<debezium-mysql-connector-version>26.10.0</debezium-mysql-connector-version>
         <dhis2-version>3.0.2</dhis2-version>
         <directory-api-version>2.1.9</directory-api-version>

Reply via email to