`
zzmccnu
  • 浏览: 73905 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Eclipse RCP 定制启动过程

阅读更多
Eclipse RCP 定制启动过程

问题:一个RCP程序,打包好后,如何双击某个工程文件,用这个RCP程序加载这个工程?换一个说法就是如何用Eclipse打开一个已有工程。

解决思路
    Eclipse平台目前是这样的,要打开一个已有的工程,先运行Eclipse程序,然后选择File菜单下面的Import来完成这个操作。RCP是基于Eclipse平台的,如何能开发出一个RCP应用程序,这个程序能够直接打开一个已有的工程?
    要完成这项功能,需要定制RCP的启动过程,Eclipse RCP程序都要实现IApplication这个接口,看看接口的源码(省略了部分注释):
package org.eclipse.equinox.app;

/**
 * Bootstrap type for an application.  An IApplication represent executable 
 * entry points into an application.  An IApplication can be configured into 
 * the Platform's org.eclipse.equinox.applications extension-point.
 *
 * <p>
 * Clients may implement this interface.
 * </p>
 * 
 * @since 1.0
 */
public interface IApplication {

	public static final Integer EXIT_OK = new Integer(0);

	public static final Integer EXIT_RESTART = new Integer(23);

	public static final Integer EXIT_RELAUNCH = new Integer(24);

	public Object start(IApplicationContext context) throws Exception;

	public void stop();
}

    从IApplication接口可以看出,要定制RCP的启动过程,就需要在重写start()方法上做文章了。现在再回到如何打开Eclipse已有工程这个问题上面。初版预计有以下步骤:
  1. 读取工程文件的路径参数(例如.project文件),该参数可以从start()方法的参数IApplicationContext context中获取。
  2. 打开一个指定的workspace,我们可以规定这个workspace只能有0个或1个工程。
  3. 将该工程加入到打开的workspace中,如同Eclipse导入工程的工程。

上面的几个步骤都是只需要在start()方法里面实现的过程,比较笼统,需要进一步细化,完善其中的细节。
1. 读取工程文件路径的,示例代码如下:
public Object start(IApplicationContext context) throws Exception {
		// log the arguments
		String[] arguments = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
		Log.info("arguments.length = " +arguments.length);
		if(arguments.length > 0) {
			Log.info("Arguments[0] = " +arguments[0]);
		}
		return super.start(context);
}

2.打开指定工作区(workspace),可以参照Eclipse启动参数,我们输入以下命令就可以让它启动后进入指定的工作区。
引用
eclipse.exe -data workspace-name

3.过程最复杂的就是如何把这个工程加入到我们打开的workspace中了。具体实现过程打算参考eclipse导入工程部分的源代码。
(未完...)
分享到:
评论
2 楼 zzmccnu 2012-08-22  
可能是你的工程所依赖的插件在新的Eclipse环境中没有找到,检查下工程依赖的插件列表。
1 楼 Ritamingming 2012-06-11  
请教您个问题:我的工程是之前做的,我现在导入工程到EClipse中,总是报
package org.eclipse.equinox.app;    错误,不存在,是什么原因。
"import org.eclipse.equinox.app";   ---can't be resolved
导致IApplication接口无法使用。

相关推荐

Global site tag (gtag.js) - Google Analytics