In Eclipse each plug-in has its own class loader and has its own class look-up path that is derived from the imported plug-ins. A separate class loader gives each plug-in a separate name space for its classes. The class loader also is responsible for triggering the activation of a plug-in. When a plug-in class loader loads the first class from a plug-in, then the plug-in is activated and the plug-in's startup() method is called.
The classes are looked-up in the following order:
-
The plug-in class loader's parents— The immediate parent of a plug-in class loader is the Eclipse boot class loader. It provides access to the Eclipse boot classes (boot.jar). The parent of the boot class loader is the standard Java system class loader, which terminates the parent chain. Notice that the application class loader, which loads classes from the system's CLASSPATH variable is not part of this chain. This means classes on the system class path are never found by Eclipse. Plug-ins are the only way to surface additional classes. The following spider diagram illustrates the parent chain:
-
The plug-in's class loader itself— It finds the classes contributed by the plug-in as specified in the run-time section of the plugin.xml manifest.
-
The plug-in class loaders of the imported/prerequisite plug-ins— A delegating URL class loader is used internally to forward the class lookup to the imported plug-ins.
本文详细介绍了Eclipse中插件的工作机制,包括插件类加载器如何为每个插件提供独立的命名空间,以及插件激活的过程。还阐述了类查找的顺序,即从Eclipse启动类加载器开始,到插件自身的类加载器,最后到导入插件的类加载器。
2492

被折叠的 条评论
为什么被折叠?



