Usually, I've been using eclipse fragments to separate my language and resource files. Each language resource, japanese, english, tagalog will have their own fragment. This time I wanted to used fragment to patch an existing plugin, and it took 3 hours for me to work it out. Here's what I've done:
1.) Create a helloworld rcp project (name it org.demo.fragment).
2.) Now I want the helloworld project to access another plugin, for example math related library (org.demo.fragment.math).
Note: in the new plugin wizard in the Options Group, uncheck all. Generate an Activator...,This plugin..., etc.
a.) create package: org.demo.fragment.math
b.) inside the new package create a class MyMath.java
c.) add a method operationA(int a, int b) that returns the sum of the 2 integer
package org.demo.fragment.math;
public class MyMath {
public static int operationA(int a, int b) {
return a + b;
}
}
3.) Now, in the plugin org.demo.fragment.math, since we want its class to be accessible in other plugin,
a.) open manifest.mf
b.) on the Runtime tab->Exported Packages, add org.demo.fragment.math
c.) also in the Build tab Add Library patch.jar, make sure it's above the '.'
4.) In the first project we have created, helloworld project, let's add the second project in the plugin.xml Dependencies tab
a.) in the helloworld ApplicationWorkbenchWindowAdvisor.preWindow method add this line:
System.out.println(MyMath.operationA(2, 4));
b.) this should output for now 6
5.) Now what I want is to patch the second project, and make changed the operation to multiplication, here's how to do
a.) create a fragment project (org.demo.fragment.math.patch), select org.demo.fragment.math as Host Plugin
b.) in org.demo.fragment.math, we should let eclipse know that it's extensible so we changed its manifest.mf file and add:
i.) Eclipse-ExtensibleAPI:
ii.) in the Build tab, Add Library patch.jar
It's all set
c.) going back into our fragment project, open manifest.mf
i.) add Eclipse-PatchFragment: true
ii.) in the Build tab, Add Library patch.jar, while patch.jar is selected click Add Folder select src
d.) create a similar package and class from the second plugin, org.demo.fragment.math, which we want to override example the MyMath.java class, let's changed the operation to multiple
package org.demo.fragment.math;
public class MyMath {
public static int operationA(int a, int b) {
return a * b;
}
}
Run the helloworld project, as you can see it now outputs 8 :-D.
manifest.mf
Plugin Project(Hello world template): org.demo.fragment
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Fragment Bundle-SymbolicName: org.demo.fragment; singleton:=true Bundle-Version: 1.0.0 Bundle-Activator: org.demo.fragment.Activator Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.demo.fragment.math;bundle-version="1.0.0" Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6Plugin Project: org.demo.fragment.math
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Math Bundle-SymbolicName: org.demo.fragment.math Bundle-Version: 1.0.0 Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Export-Package: org.demo.fragment.math Eclipse-ExtensibleAPI: true Bundle-ClassPath: patch.jar, .Fragment Project: org.demo.fragment.math.patch
Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Patch Bundle-SymbolicName: org.demo.fragment.math.patch Bundle-Version: 1.0.0 Fragment-Host: org.demo.fragment.math;bundle-version="1.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Eclipse-PatchFragment: true
hi can i ask you regarding this post?
ReplyDeletethanks
Sure :-D
ReplyDeleteHello,
ReplyDeleteCan you please post the source code of your exemple ?
thanks,
thysdrus
Didn't get my program running till I found your page and this little:
ReplyDeleteEclipse-ExtensibleAPI: true
Thanks !
It doesn't work wrapping the host bundle (binary project in Eclipse) ?
ReplyDeleteI cant make it work.
Post a Comment