HowTo load database-driver dynamically [message #320939] |
Thu, 04 October 2007 05:29  |
Eclipse User |
|
|
|
Originally posted by: tobias.soloschenko.mxcit.de
Hello,
I've a little problem by loading driver at runtime, I posted it already in
another newsgroup but even there noone had an idea. So here is the
description:
---------
Hello,
Is there any way to add jars dynamically to the osgi context? I've got
the
problem to use a folder where users can add drivers and those drivers
have
to load dynamically. So I can't define it in plugin.xml > Runtime >
Classpath.
I'm using Spring in the rcp context and the request to any driver
classes
is delegated to the
org.eclipse.core.runtime.internal.adaptor.ContextFinder. The
ContextFinder itself looks into the classpath of the plugin where no
Drivers
are found and then the app crashes.
I heard about a ClassLoadingHook and tried it already with vm
arguments.
Thanks!
|
|
|
|
|
Re: HowTo load database-driver dynamically [message #321246 is a reply to message #321178] |
Fri, 12 October 2007 07:04  |
Eclipse User |
|
|
|
Originally posted by: tobias.soloschenko.mxcit.de
Hello,
no I can't find any documentation about those Hook's, so I solved it by
writing my own classLoader and set it as ContentClassLoader which uses the
URLClassLoader:
ExternalClassLoader myLoader = new ExternalClassLoader();
Thread.currentThread().setContextClassLoader(myLoader);
because I'm using a datapool called c3p0 with Spring and the sources of
c3p0 are free available I changed the programcode where they are locating
drivers with Class.forName("...") to
Class.forName("...",true,myClassLoader);
I configured the driverLoader to load drivers from the install-folder with
Platform.getInstallLocation().getURL().getFile()
Now I can put drivers into the eclipse directory (for testing) or into the
programfolder when the product has been exported and they are loaded
dynamically.
Thats a very dirty solution, may it is possible in a better way but how?
best regards
Tobias
|
|
|
Powered by
FUDForum. Page generated in 0.05347 seconds