karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Ward <tim.w...@paremus.com>
Subject Re: java.lang.ClassNotFoundException: org.h2.Driver from bundle ..
Date Sat, 01 Jul 2017 23:08:56 GMT

The org.osgi.service.jdbc.DataSourceFactory service is an OSGi standard, not part of Karaf
(hence the org.osgi package name). You can find the specification chapter in the OSGi compendium.
If you look at the H2 bundle you'll also see that H2 actually implements this standard directly.

Anyway, your problem occurs because you are passing a String class name to DBCP. DBCP is then
attempting to dynamically load this class, which fails because the DBCP bundle has no visibility
of the database implementation class (which is as it should be). Effectively the BasicDataSource
can't be configured safely in OSGi because of this. 

You can assemble a DBCP pool in your blueprint file, using the DataSourceFactory service to
get hold of a DataSource or Driver, and setting up the pool using a set of beans (this is
described in the DBCP docs for custom pool setup). 

If you insist on not using the standard then you need to embed the whole of DBCP into your
bundle and add the imports for the database drivers, which is even smellier than what was
being suggested in my previous email as you will also drag in DBCP's dependencies. 

Another standard (technically a draft pending release later this year) that would probably
help you is OSGi Transaction Control. This makes it a lot easier to safely get hold of a database
connection and to use it in transactions. There's an implementation of this hosted at Apache
Aries if you're interested.


Sent from my iPhone

> On 1 Jul 2017, at 23:17, smunro <stephen.ross.munro@gmail.com> wrote:
> Hello Timothy,
> Thanks for the quick reply.
> The issue is that my manager is pushing me to be container agnostic and to
> avoid tying myself to Karaf. Personally, I'd rather use pax-jdbc but I am
> not permitted to do so and I agree about your comment regarding code smells
> for tying to a specific jdbc implementation.
> What I have at the moment is a blueprint file with a dbcp BasicDataSource,
> this file has two configurations. One for sql server and another for h2. I
> had a lot of of trouble getting SQL Server to work using the data source
> strategy, which was enough for my manager to push me to use a direct
> connection for both.
> I've tried both setting the Bundle-Classpath and Import-Package with org.h2
> and both seem to result in an error. I have h2 defined as a pom dependency,
> is there anything else I am missing?
> --
> View this message in context: http://karaf.922171.n3.nabble.com/java-lang-ClassNotFoundException-org-h2-Driver-from-bundle-tp4050894p4050897.html
> Sent from the Karaf - User mailing list archive at Nabble.com.

View raw message