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?
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.
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)
In tab 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):
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!"); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With