破门点滴(Java技术版)

在日常学习和工作中记录

  BlogJava :: 首页 ::  :: 聚合  :: 管理
  15 Posts :: 7 Stories :: 36 Comments :: 0 Trackbacks
 

关于ClassLoader 问题的分析:

EclipeClassLoader 创建:


org.eclipse.core.runtime.adaptor.EclipseElementFactory

public org.eclipse.osgi.framework.adaptor.BundleClassLoader createClassLoader

(ClassLoaderDelegate delegate, ProtectionDomain domain, S

tring[] bundleclasspath, AbstractBundleData data) {

              
return new EclipseClassLoader(delegate, domain, 

bundleclasspath, data.getAdaptor().getBundleClassLoaderParent(), data);

       }


获取ClassLoaderParent 的方法,使用了EclipseAdaptor

Adaptor getBundleClassLoaderParent() 如何去定 bundleClassLoaderParent?


 1org.eclipse.osgi.framework.adaptor.core. AbstractFrameworkAdaptor
 2
 3/**
 4
 5        * The BundleClassLoader parent to use when creating BundleClassLoaders.
 6
 7        * The behavior of the ParentClassLoader will load classes
 8
 9        * from the boot strap classloader.
10
11        */

12
13       protected static ClassLoader bundleClassLoaderParent;
14
15 
16
17       static {
18
19              // check property for specified parent
20
21              String type = 
22
23System.getProperty(PROP_PARENT_CLASSLOADER, PARENT_CLASSLOADER_BOOT);
24
25              if (PARENT_CLASSLOADER_FWK.equalsIgnoreCase(type))
26
27                     bundleClassLoaderParent = FrameworkAdaptor.class.getClassLoader();
28
29              else if (PARENT_CLASSLOADER_APP.equalsIgnoreCase(type))
30
31                     bundleClassLoaderParent = ClassLoader.getSystemClassLoader();
32
33              else if (PARENT_CLASSLOADER_EXT.equalsIgnoreCase(type)) {
34
35                     ClassLoader appCL = ClassLoader.getSystemClassLoader();
36
37                     if (appCL != null)
38
39                            bundleClassLoaderParent = appCL.getParent();
40
41              }

42
43 
44
45              // default to boot classloader
46
47              if (bundleClassLoaderParent == null)
48
49                     bundleClassLoaderParent = new ParentClassLoader();
50
51       }

52
53


如果使用了了boot Classloader ParentClassLoader 是新建的 boot,这里分析看来应该使用framework 或者系统的ClassLoader吧。

根据以上的分析,对Triones的启动环境进行了调整:

1、直接引用 org.eclipse.osgi 中的启动包,避免使用反射。注:可以直接调用EclipseStarter.run(null) 了。

2、Triones Runtime 拆分成为 triones-core.jar (包括主要的服务接口 ItrionesFramework 等)和 triones-runtime.jar (Triones Runtime Eclipse插件)

3、修改 Eclipse config.ini 配置。

# osgi classloader :

osgi.parentClassloader = fwk

根据上面的分析, fwk 表示使用 FrameworkAdaptor ClassLoader 作为OSGiparent classloader

bundleClassLoaderParent = FrameworkAdaptor.class.getClassLoader();



不得窥道门,不得悟佛门,不得入窄门,实乃破门。
posted on 2005-11-28 16:25 破门 阅读(512) 评论(0)  编辑  收藏 所属分类: Triones

只有注册用户登录后才能发表评论。


网站导航: