Equinox:配置Parent classloader

來源:互聯網
上載者:User

可通過修改啟動的osgi.ParentClassLoader來改變這個parent classloaer,預設採用是boot。
可選的其他值有app、ext、fwk。
app對應的SystemClassLoader。即系統類別載入器
ext對應的是SystemClassLoader的parent,即擴充類載入器
fwk對應的為啟動equinox的classloader。

可在org.eclipse.osgi.baseadaptor.BaseAdaptor看到如下代碼

// System property used to set the parent classloader type (boot is the default)
 private static final String PROP_PARENT_CLASSLOADER = "osgi.parentClassloader"; //$NON-NLS-1$
 // A parent classloader type that specifies the application classloader
 private static final String PARENT_CLASSLOADER_APP = "app"; //$NON-NLS-1$
 // A parent classloader type that specifies the extension classlaoder
 private static final String PARENT_CLASSLOADER_EXT = "ext"; //$NON-NLS-1$
 // A parent classloader type that specifies the boot classlaoder
 private static final String PARENT_CLASSLOADER_BOOT = "boot"; //$NON-NLS-1$
 // A parent classloader type that specifies the framework classlaoder
 private static final String PARENT_CLASSLOADER_FWK = "fwk"; //$NON-NLS-1$
 // The BundleClassLoader parent to use when creating BundleClassLoaders.
 private static ClassLoader bundleClassLoaderParent;
 static {
  // check property for specified parent
  String type = FrameworkProperties.getProperty(BaseAdaptor.PROP_PARENT_CLASSLOADER, BaseAdaptor.PARENT_CLASSLOADER_BOOT);
  if (BaseAdaptor.PARENT_CLASSLOADER_FWK.equalsIgnoreCase(type))
   bundleClassLoaderParent = FrameworkAdaptor.class.getClassLoader();
  else if (BaseAdaptor.PARENT_CLASSLOADER_APP.equalsIgnoreCase(type))
   bundleClassLoaderParent = ClassLoader.getSystemClassLoader();
  else if (BaseAdaptor.PARENT_CLASSLOADER_EXT.equalsIgnoreCase(type)) {
   ClassLoader appCL = ClassLoader.getSystemClassLoader();
   if (appCL != null)
    bundleClassLoaderParent = appCL.getParent();
  }
  // default to boot classloader
  if (bundleClassLoaderParent == null)
   bundleClassLoaderParent = new ParentClassLoader();
 }

 // Empty parent classloader.  This is used by default as the BundleClassLoader parent.
 private static class ParentClassLoader extends ClassLoader {
  protected ParentClassLoader() {
   super(null);
  }
 }
 
 修改配置。可在eclipse中做小實驗調試一番。
run configurations--->arguments000>VM arguments
比如添加:
-Dosgi.ParentClassLoader=ext

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.