eclipse fragment tutorial - Patch your eclipse plugin using eclipse fragment
Tech-Today

eclipse fragment tutorial - Patch your eclipse plugin using eclipse fragment


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.6

Plugin 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




- Hibernate Ogm For Mongodb
So lately I've been playing with Hibernate OGM MongoDB's latest version 5.4.0.Beta2 but I'm not able to run a demo project created from wildfly-javaee7-war archetype following the documentation. Here are the changes I've made to make...

- How To Create A Modularized Ear Project In Maven
This post is one way of creating a typical javaee6 maven project that contains ear, web, ejb and api. The output of course is an ear file that contains (web, ejb and api). How it looks like (assuming our top project is named ipiel): +ipiel  +ipiel-ear...

- How To Change The Context Url In Jboss Or Wildfly
Normally when we create a new war or ear, for example demo-project.war or demo-project.war inside demo-project.ear. The context root or url to which we can access the web application is: http://localhost:8080/demo-project But what if we want to change...

- Using Gridview Layout In Android
So, lately I've been relearning android development and as I expected there were already a lot of changes since I last code in it (eclair). Like the concept of Fragment (which I love), unfortunately statistics show that most of the users are still...

- Eclipse-rcp Calling A Command With Parameter In Code
In case you come up with the same situation as mine, here's how I've done it. 1.) in your eclipse-rcp's project's plugin.xml create a new command with a parameter, set the ids Example -commandId: org.ipiel.demo.commands.click -commandParameterId:...



Tech-Today








.