Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Plugin 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?

like image 873
SteveT Avatar asked Mar 23 '09 15:03

SteveT


People also ask

What are Eclipse fragments?

A fragment is an optional attachment to another plug-in. This other plug-in is called the host plug-in. At runtime the fragment is merged with its host plug-in. Therefore, for the Equinox runtime, both projects are just one.


1 Answers

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

  2. 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)

  3. In tab Extentions click Add.. and add org.eclipse.ui.startup and browse class which implements org.eclipse.ui.IStartup class.

  4. 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!");

    }


}
like image 90
Michal Bernhard Avatar answered Sep 22 '22 14:09

Michal Bernhard