[总结] Eclispe 插件面试题

来源:互联网 发布:手机国外电视直播软件 编辑:程序博客网 时间:2024/05/21 17:35

经过无数的面试,我总结一些题,给出一些参考答案。(如果你有新的题,可以留言啊。)


1  关于SWT 的非UI 线程问题( 即 SWT 抛  org.eclipse.swt.SWTException: Invalid thread access

      如果在Job中加上改变UI的代码就会失败。

      原因如下:
        如果是在非UI线程中调用UI,SWT就会抛出一个SWTException,要在一个非UI线程改变UI的话有几种技术:

        第一种,用:
             Display#syncExec(Runnable)或
             Diaplay#asyncExec(Runnable)

        第二种:
        已经开发了另外一种Job,就是UIJob,可以直接在它里面运行改变UI的代码,其实它就是在SWT的asyncExec()方法里运行的.所有继承UIJob的类应该覆写runInUIThread方法而不是run方法。

   来自:http://tech.ccidnet.com/art/3745/20060214/428173_3.html


2  关于资源释放的问题(Eclipse 的原则:谁创建,谁释放)

   可以参见:   关于Eclipse 的Image 和dispose 方法


3  菜单的关联问题(如:在什么地方出现,满足什么条件出现)

   1) 需求:想自己开发一个eclipse插件,就是不知道怎么在eclipse的package explorer中增加自己的右键菜单?
                 像MyEclipse就有,easyexplorer也有,但是我不知道怎么做,哪位能手把手教我下?

         解决方案:

               1) 添加 Extension: org.eclipse.ui.popupMenu
               2) 再添加 ViewerContribution 并给"targetID*"赋值为org.eclipse.jdt.ui.PackageExplorer.
               3) 再在此ViewerContribution下添加 Action 或 Menu

               具体参考  http://www.eclipse.org/articles/article.php?file=Article-action-contribution/index.html

          摘自: http://topic.csdn.net/u/20081130/21/6a46c62d-f5bb-465b-b5fd-5eee8b6c09b9.html


4  OSGI 的类加载问题

    可以参见

                osgi 入门 三 关于类装载机制

                http://zyl.javaeye.com/blog/334326

                Equinox加载Bundle Class的实现

                http://gocom.primeton.com/blog19041_15944.htm?PHPSESSID=%3C


5  Bundle 之间类的引用

    被引用的插件要export 出去包。

    引用别人的插件要 import 包,可以使用Require-Bundle 与 Import-Package。


6  Require-Bundle 与 Import-Package 的区别

     To be clear, require-bundle and import-package are not equivalent, but they certainly overlap.

     A simple way of looking at require-bundle is that it is a shorthand way of importing every package that is exported

by another bundle, but it a slightly different than this in reality.

     Import-package terminates when a class from the package is not found (i.e., packages are assumed to

be self-contained), while require-bundle does NOT terminate when a class from a package is not found, it

continues searching other required bundles as well as the local bundle itself (i.e., packages are assumed to be split).

   来自: http://blog.csdn.net/floyddcn/archive/2008/05/07/2410653.aspx


    在equinox中可以采用两种方式来实现这点,分别是Require-Bundle和Import-Package的方式,就像Jeff在PPT中所说一样,Require-Bundle适合用于需要引用其他Bundle中的资源的情况,但它就使得bundle产生了紧耦合,所以推荐使用Import-Package,Import-Package保证了松耦合,在实际的使用中来看,Import-Package能够使得面向接口的编程得以强制进行,当然,不是说require-bundle就一无是处了,^_^

   来自:http://www.blogjava.net/BlueDavy/archive/2006/04/05/39438.html



Java 的基础知识 

可以参考:  http://wenku.baidu.com/view/098d6afdc8d376eeaeaa31bd.html

原创粉丝点击