Eclipse插件片段 [英] Eclipse Plugin Fragment

查看:122
本文介绍了Eclipse插件片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人有一个hello world样本或教程来创建Eclipse插件片段?



我有一个工作的主机插件,为了简单起见,只是这个...

  public void start(BundleContext context)throws Exception {
System.out.println 你好....);
super.start(context);
plugin = this;
}

public void stop(BundleContext context)throws异常{
System.out.println(Goodbye ...);
plugin = null;
super.stop(context);
}

简单,工作。现在我要添加一个片段到该主机,这似乎不像创建插件主机那么简单。我只是看不到如何创建一个片段项目并添加逻辑。假设我只想做一些简单的事情,并在 start() stop()中的Goodbye2中打印一个Hello2 。有人可以给我一个工作示例吗?

解决方案

Eclipse - >文件 - >新建... - >片段项目 - >设置主机插件(您的工作空间或目标平台中的插件)。



打开插件清单编辑器(您可以通过点击build.properties ,manifest.mf或fragment.xml - 如果没有这样的文件,手动创建),并在扩展名中单击添加,并添加org.eclipse.ui.startup并浏览类实现org.eclipse.ui.IStartup类。创建这个类并实现它。您需要实现方法earlyStartup(),它是片段的入口点。



注意:以下行仅仅是示例。我没有测试它,所以可能有错误...



所有你需要的是这(这是项目结构/目录结构):




  • 片段项目 - 根目录


    • / META-INF


      • MANIFEST.MF


        • / src (这是源目录)


          • FragmentStartClass .java (实现org.eclipse.ui.IStartup界面和earlyStartup方法)


        • build.properties

        • fragment.xml




      META-INF / MANIFEST.MF 内容:

       
      Manifest-版本:1.0
      Bundle-ManifestVersion:2
      Bundle-Name:FragmentProject
      Bundle-SymbolicName:FragmentProject; singleton:= true
      Bundle版本:1.0.0
      Bundle-ClassPath:src / ,.
      片段主机:* HostPluginProjectSymbolicName *; bundle-version =1.0.0
      Bundle-RequiredExecutionEnvironment:J2SE-1.5
      要求包:

      build.properties 内容:

       
      source .. = src,\
      output .. = bin /
      bin.includes = META-INF /,
      。,
      fragment.xml

      fragment.xml 内容:

       
      <?xml版本= QUOT; 1.0"编码= QUOT; UTF-8英寸;?>
      <?eclipse version =3.2?>
      < fragment>
      < extension
      point =" org.eclipse.ui.startup>>
      < startup
      class =FragmentStartClass>
      < / startup>
      < / extension>
      < / fragment>

      FragmentStartClass.java 内容:

       
      import org.eclipse.ui.IStartup;


      public class FragmentStartClass实现IStartup {

      public void earlyStartup(){
      System.out.println(Hello World From Fragment!) ;

      }


      }


      Does anyone have a "hello world" sample or tutorial for creating an Eclipse plugin fragment?

      I have a working host plugin that, for the sake of simplicity, is just this...

      public void start(BundleContext context) throws Exception {
          System.out.println("Hello....");
          super.start(context);
          plugin = this;
      }
      
      public void stop(BundleContext context) throws Exception {
          System.out.println("Goodbye...");
          plugin = null;
          super.stop(context);
      }
      

      Simple enough and works. Now I want to add a fragment to that host, which seems not as simple as creating a plugin host. I just don't see how to create a fragment project and add logic to it. Let's say I just want to do something simple and have the fragment to print a "Hello2" at start() and "Goodbye2" at stop(). Can someone give me a working example?

      解决方案

      Eclipse -> File -> New... -> Fragment project -> set the host plugin (which is either in your workspace or in plugins in target platform).

      Open "Plugin manifest editor" (you can do it by clicking on build.properties, manifest.mf or fragment.xml - if there is no such a file, create it by hand) and in tab called "Extentions" click "Add.." and add "org.eclipse.ui.startup" and browse class which implements org.eclipse.ui.IStartup class. Create this class and implement it. You need to implement method earlyStartup() which is entry point to the fragment.

      Note: The lines below are just example. I didn't test it so there might be errors...

      All you need is this (this is project structure / directory structure):

      • Fragment-Project - root dir
        • /META-INF
          • MANIFEST.MF
        • /src (which is source directory)
          • FragmentStartClass.java (which implement org.eclipse.ui.IStartup interface and earlyStartup method)
        • build.properties
        • fragment.xml

      META-INF/MANIFEST.MF content:

      Manifest-Version: 1.0 
      Bundle-ManifestVersion: 2 
      Bundle-Name: FragmentProject 
      Bundle-SymbolicName: FragmentProject;singleton:=true 
      Bundle-Version: 1.0.0 
      Bundle-ClassPath: src/,. 
      Fragment-Host: *HostPluginProjectSymbolicName*;bundle-version="1.0.0" 
      Bundle-RequiredExecutionEnvironment: J2SE-1.5 
      Require-Bundle:  
      

      build.properties content:

      source.. = src,\
      output.. = bin/
      bin.includes = META-INF/,
                    .,
                        fragment.xml
      

      fragment.xml content:

      <?xml version="1.0" encoding="UTF-8"?>
      <?eclipse version="3.2"?>
      <fragment>
         <extension
               point="org.eclipse.ui.startup">
            <startup
                  class="FragmentStartClass">
            </startup>
         </extension>
      </fragment>
      

      FragmentStartClass.java content:

      import org.eclipse.ui.IStartup;
      
      
      public class FragmentStartClass implements IStartup {
      
          public void earlyStartup() {
             System.out.println("Hello World From Fragment!");
      
          }
      
      
      }
      

      这篇关于Eclipse插件片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆