In my OSGi environment I am trying to preload a database driver for further usage. Normally, this can be done like that:
Class.forName("com.mysql.jdbc.Driver");
After that, a connection can be created. However, if I use that in OSGi under Felix, he says that the class cannot be found (ClassNotFoundException
) and the connection cannot be created. But when I do something like that (try-catch
is omitted):
com.mysql.jdbc.Driver d = new com.mysql.jdbcDriver
Class.forName("com.mysql.jdbc.Driver");
Then everything works fine and the connection is created. However, this is not very pretty because the driver class cannot be exchanged.
Is there a way to load the class with the first method? I assume that I have to provide the correct class loader. But where do I get that from?
The MySQL driver is provided as an OSGi wrapper bundle.