Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [pde-dev] No joy bundleing java libraries with plugins

You need to make sure you load the driver with the correct classloader.

We ran into these kinds of problems with resources. For instance we have a "ui" plugin and then an "application.ui" plugin that depends on ui. Ui has a resource loading/caching utility class (we are running Swing on top of Eclipse so we can't use all the cool little JFace/Workbench utilities) but our utility class's classloader can't see the resources directory in the application.ui plugin. We modified our utility to take both a url and a classloader. For instance: getIcon(Url url, Classloader classloader). In our application.ui we make the call: getIcon(url, getClass().getClassloader) and all of our classpath problems go away.

A second type of classloader problem reared its ugly head when we wanted to use a specific version of xerces in one of our plugins (our XML database requires us to have their version of xerces in the classpath). We had no control of the classloading though, because xerces is loaded behind the scenes in the vendor's proprietary database driver. We traced down that ultimately the context classloader was loading the driver, but the context classloader wasn't currently set to the plugin's classloader. We put in a little hack around the driver initialization:

Classloader odlClassloader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassloader());
driver.init();
Thread.currentThread().setContextClassLoader(oldClassloader);

I am definately not an expert in classloading (in fact I have no clue how the context classloader works), but I have found that these tricks work in my application.

Thanks,
-Phil

Nico Guba wrote:

First of all, Hello :)

Eclipse 3.0M8

I searched the archives (not much joy) and looked for a few days in tons of
docs but still have absolutely no joy bundleing a jdbc driver with my plugin
(ie I'd like to add a jar file to the plugins runtime and distribute it with
the plugin).

I think I've been through all the wizzards and property sheets by now but I
still cannot get the plugin to 'see' that jar file.

I even added the jar to the JRE system library (which alas the pde seems to
see) but yet STILL no joy just running he plugin. BOOM!

java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
	at
org.eclipse.osgi.framework.internal.core.BundleLoader.findClass(BundleLoader
.java:348)
	at
org.eclipse.osgi.framework.adaptor.core.AbstractClassLoader.loadClass(Abstra
ctClassLoader.java:116)
	at java.lang.ClassLoader.loadClass(Unknown Source)

Hmmm,  I must have overlooked something in the documentation explaining
this.  Has anybody got any pointers as to where I need to look (probably
again)?


_______________________________________________
pde-dev mailing list
pde-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/pde-dev




Back to the top