现在的位置: 首页 > 综合 > 正文

【OSGI】Eclipse中创建Plug-in项目时的Target platform选项说明

2014年10月08日 ⁄ 综合 ⁄ 共 3460字 ⁄ 字号 评论关闭

新建Plug-in项目时,需要选择Target platform:

其中有三种选择:

1、Eclipse version

2、an OSGi framework: Equinox

3、an OSGi framework: standard

什么意思呢?

Eclipse version 指的是Eclipse UI 插件这样的运行方式. 

an OSGI framework 指的是运行于OSGI下的,非UI的插件. 
    选项: Equinox 指的是,使用Equinox(Eclipse的OSGI实现) 
    选项: standard 指的是,使用标准的OSGI实现 

下面具体说明他们的差别: 

1. 自动生成代码的区别:
 
选择Eclipse version, 那么默认生成的Activator就是继承与AbstractUIPlugin. 

[java] view
plain
copy

  1. package helloservive04;  
  2.   
  3. import org.eclipse.ui.plugin.AbstractUIPlugin;  
  4. import org.osgi.framework.BundleContext;  
  5.   
  6. /** 
  7.  * The activator class controls the plug-in life cycle 
  8.  */  
  9. public class Activator extends AbstractUIPlugin {  
  10.   
  11.     // The plug-in ID  
  12.     public static final String PLUGIN_ID = "HelloServive04"//$NON-NLS-1$  
  13.   
  14.     // The shared instance  
  15.     private static Activator plugin;  
  16.       
  17.     /** 
  18.      * The constructor 
  19.      */  
  20.     public Activator() {  
  21.     }  
  22.   
  23.     /* 
  24.      * (non-Javadoc) 
  25.      * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) 
  26.      */  
  27.     public void start(BundleContext context) throws Exception {  
  28.         super.start(context);  
  29.         plugin = this;  
  30.     }  
  31.   
  32.     /* 
  33.      * (non-Javadoc) 
  34.      * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) 
  35.      */  
  36.     public void stop(BundleContext context) throws Exception {  
  37.         plugin = null;  
  38.         super.stop(context);  
  39.     }  
  40.   
  41.     /** 
  42.      * Returns the shared instance 
  43.      * 
  44.      * @return the shared instance 
  45.      */  
  46.     public static Activator getDefault() {  
  47.         return plugin;  
  48.     }  
  49.   
  50. }  


选择Equinox或者standard,
那么默认的Activator就是实现了BundleActivator接口. 

[java] view
plain
copy

  1. package helloservice02;  
  2.   
  3. import org.osgi.framework.BundleActivator;  
  4. import org.osgi.framework.BundleContext;  
  5.   
  6. public class Activator implements BundleActivator {  
  7.   
  8.     private static BundleContext context;  
  9.   
  10.     static BundleContext getContext() {  
  11.         return context;  
  12.     }  
  13.   
  14.     /* 
  15.      * (non-Javadoc) 
  16.      * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) 
  17.      */  
  18.     public void start(BundleContext bundleContext) throws Exception {  
  19.         Activator.context = bundleContext;  
  20.     }  
  21.   
  22.     /* 
  23.      * (non-Javadoc) 
  24.      * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) 
  25.      */  
  26.     public void stop(BundleContext bundleContext) throws Exception {  
  27.         Activator.context = null;  
  28.     }  
  29.   
  30. }  


2. MANIFEST.MF的区别: 
Eclipse version,打开的MANIFEST.MF的编辑器,
它有Extensions 和 Extension Points这两个设置页面. 


Equinox或者standard,开的MANIFEST.MF的编辑器,
是没有Extensions 和 Extension Points这两个设置页面. 



这也说明一个区别: Ecliopse平台不仅仅实现了OSGI, 同时, 还使用了自己的Plugin机制, 也就是Extensions和Extensions Points机制. 

也就是Eclipse并不是一个完全的OSGI, 而是一个OSGI 与 自己的Plugin机制的结合体. 


Equinoxstandard发现一个小小的区别:

对于EquinoxMANIFEST.MF中多了一项默认设置:

Bundle-ActivationPolicy: lazy

standardMANIFEST.MF中没有发现。

后记: 
发现Eclipse的Help里面有一些相关的信息: 

引用
Eclipse vs. OSGi Framework 
The Eclipse vs. OSGi framework choice acts as pre-filter to determine what initial pages will be visible in the plug-in manifest editor when it opens. 

Since the extension registry is Eclipse-specific content, the Extensions and Extension Points pages of the manifest editor are visible only when the Eclipse version option is chosen. 

Equinox vs. Standard 
When targeting an OSGi framework, you have a choice between the Equinox and standard frameworks. The Equinox OSGi framework augments the MANIFEST.MF content with Eclipse-specific headers (e.g. Eclipse-LazyStart) and directives (e.g. x-friends). If you do not
wish to use these Eclipse-specific headers and attributes, then choose the standard option. 

抱歉!评论已关闭.