2

I am having a servicemix bundle which tries to load jdbc driver and fails with message

Cannot load JDBC driver class 'com.mysql.jdbc.Driver'

Here is my pom.xml file

      <!-- MySQL -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.32</version>
    </dependency>

    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.4</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-pool2</artifactId>
        <version>2.4.2</version>
    </dependency>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <Import-Package>
                        com.mysql.jdbc,
                        *
                    </Import-Package>
                    <DynamicImport-Package>
                        *
                    </DynamicImport-Package>
                </instructions>
            </configuraiton>
        </plugin>

I have below lines mentioned in my features.xml file which is added to karaf using features:addurl command.

<bundle>wrap:mvn:mysql/mysql-connector-java/5.1.32</bundle>
<bundle>wrap:mvn:commons-dbcp/commons-dbcp/1.4</bundle>
<bundle>wrap:mvn:commons-pool/commons-pool/1.6</bundle>
рüффп
  • 5,172
  • 34
  • 67
  • 113
veer7
  • 20,074
  • 9
  • 46
  • 74
  • Have you checked https://stackoverflow.com/questions/29245102/maven-java-lang-classnotfoundexception-com-mysql-jdbc-driver? – Ori Marko Sep 14 '17 at 08:09
  • Is there a route that is defined, if so please post it? Is the mysql-connector installed? – J_D Sep 14 '17 at 08:32
  • @user7294900: mvn clean install works perfectly fine. The issue I am facing is something to do with osgi import - export – veer7 Sep 14 '17 at 09:38
  • @J_D: There are many entries in `route print`. Should I look for any specific entry? – veer7 Sep 14 '17 at 09:52

2 Answers2

1

Have you seen ClassNotFoundException: com.mysql.jdbc.Driver not found while using service mix? The user added the below to the Pom:

<osgi-import-package>
  org.apache.commons.dbcp
</osgi-import-package>

<dependency>
  <groupId>org.apache.servicemix.bundles</groupId>
  <artifactId>org.apache.servicemix.bundles.commons-dbcp</artifactId>
  <version>1.4_3</version>
</dependency>

And also changed the route from

<bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">

to

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
J_D
  • 740
  • 8
  • 17
  • `servicemix.bundles` for `dbcp` is nothing but `bundle wrap` which I am already achieving by `wrap:mvn:mysql/mysql-connector-java/5.1.32 wrap:mvn:commons-dbcp/commons-dbcp/1.4 wrap:mvn:commons-pool/commons-pool/1.6` and also I am already using dbcp as data source in my code so don't need to change that. I have update my question. – veer7 Sep 15 '17 at 06:15
0

I fixed this issue by adding the servicemix wrapper jar for dbcp @https://mvnrepository.com/artifact/org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-dbcp/1.4_3

Resulting pom entry

    <dependency>
        <groupId>org.apache.servicemix.bundles</groupId>
        <artifactId>org.apache.servicemix.bundles.commons-dbcp</artifactId>
        <version>1.4_3</version>
    </dependency>

Note: while using karaf or any OSGi always give attention to META-INF/MANIFEST.MF of bundle/jar file to see what it imports(Import-Package) and what it exports(Export-Package)

As the below karaf-console screenshot of dbcp bundle, com.mysql.jdbc pakage is imported for servicemix dbcp

enter image description here

The same import as in screenshot should have apeared for <bundle>wrap:mvn:commons-dbcp/commons-dbcp/1.4$Import-Package=com.mysql.jdbc</bundle> but in vain.

veer7
  • 20,074
  • 9
  • 46
  • 74