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

12 篇文章 0 订阅
10 篇文章 0 订阅

新建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. 

package helloservive04;

import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * The activator class controls the plug-in life cycle
 */
public class Activator extends AbstractUIPlugin {

	// The plug-in ID
	public static final String PLUGIN_ID = "HelloServive04"; //$NON-NLS-1$

	// The shared instance
	private static Activator plugin;
	
	/**
	 * The constructor
	 */
	public Activator() {
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext context) throws Exception {
		super.start(context);
		plugin = this;
	}

	/*
	 * (non-Javadoc)
	 * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext context) throws Exception {
		plugin = null;
		super.stop(context);
	}

	/**
	 * Returns the shared instance
	 *
	 * @return the shared instance
	 */
	public static Activator getDefault() {
		return plugin;
	}

}

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

package helloservice02;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

	private static BundleContext context;

	static BundleContext getContext() {
		return context;
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext bundleContext) throws Exception {
		Activator.context = null;
	}

}

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.


可参见:
http://www.ibm.com/developerworks/cn/opensource/os-ecl-osgi/index.html

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
How to develop, build, test, package, and release Eclipse plug-ins with features for Eclipse 3.x and Eclipse 4.x Overview Create plug-ins to extend the Eclipse runtime covering Eclipse 3.x and the changes required for Eclipse 4.x Plug-ins from design to distribution — wide coverage of the entire process No prior OSGi or Eclipse plug-in development experience necessary In Detail As a highly extensible platform, Eclipse is used by everyone from independent software developers to NASA. Key to this is Eclipse’s plug-in ecosystem, which allows applications to be developed in a modular architecture and extended through its use of plug-ins and features. "Eclipse Plugin Development by Example: Beginner's Guide" takes the reader through the full journey of plug-in development, starting with an introduction to Eclipse plug-ins, continued through packaging and culminating in automated testing and deployment. The example code provides simple snippets which can be developed and extended to get you going quickly. This book covers basics of plug-in development, creating user interfaces with both SWT and JFace, and interacting with the user and execution of long-running tasks in the background. Example-based tasks such as creating and working with preferences and advanced tasks such as well as working with Eclipse’s files and resources. A specific chapter on the differences between Eclipse 3.x and Eclipse 4.x presents a detailed view of the changes needed by applications and plug-ins upgrading to the new model. Finally, the book concludes on how to package plug-ins into update sites, and build and test them automatically. What you will learn from this book How to create plug-ins for Eclipse 3.x and 4.x and automatically test plug-ins with JUnit How to display tree and table information in views What are the specific differences between the Eclipse 3.x model and the Eclipse 4.x model How and when to build user interfaces from SWT and JFace How to run tasks in the background and update the user interface asynchronously How to build plug-ins, features and update sites with Maven Tycho and automate user interface tests with SWTBot How to store and obtain preferences, and how to integrate with the Preferences panel How to work with the Eclipse resources model for creating and updating files and reporting errors to the user Approach A Beginner's Guide following the "by Example" approach. There will be 5-8 major examples that will be used in the book to develop advanced plugins with the Eclipse IDE. Who this book is written for This book is for Java developers who are familiar with Eclipse as a Java IDE and are interested in learning how to develop plug-ins for Eclipse. No prior knowledge of Eclipse plug-in development or OSGi is necessary, although you are expected to know how to create, run, and debug Java programs in Eclipse. Product Details Paperback: 348 pages Publisher: Packt Publishing (June 20, 2013) Language: English ISBN-10: 1782160329 ISBN-13: 978-1782160328

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值