Class Loading and Eclipse Plugins

Aus SDQ-Wiki

Problem: Eclipse applications do not use the standard Java ClassLoader. Instead they use multiple class loaders. This means that each plugin has its own ClassLoader that has access to the plugin and all of the dependencies the plugin defines, but not for instance to the CLASSPATH environment variables.

This can cause issues in libraries that are dependencies of your plugins if they use the ClassLoader. For example the "Class.forName(..)" methods in such libraries do not have access to the same classpath as your plugin, because this call accesses the standard Java ClassLoader.

Solution: One solution, if you have access to the library using "Class.forName(..)" is to pass the ClassLoader of the plugin (this.getClass().getClassLoader()) to the library, so that the library can use that.

Good information on the issues and solutions is available in the book "Rich-Client-Entwicklung mit Eclipse 3.3" by Berholt Daum, ISBN-10: 3-89864-503-7, ISBN-13: 978-3-89864-503-4

Related Articles

Keywords: Eclipse, Class Loader, ClassNotFoundException, NoClassDefFoundError, Plugin, classForName