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.mforfragment.xml– if there is no such a file, create it by hand)In tab Extentions click Add.. and add
org.eclipse.ui.startupand browse class which implementsorg.eclipse.ui.IStartupclass.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):
META-INF/MANIFEST.MF content:
build.properties content:
source.. = src,\ output.. = bin/ bin.includes = META-INF/, ., fragment.xmlfragment.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!"); } }