-
Notifications
You must be signed in to change notification settings - Fork 51
Create OSGi bundle and use it in Equinox app
Andrey Hihlovskiy edited this page Apr 22, 2014
·
32 revisions
Provided that we already prepared Equinox app for multiproject build, we can now create OSGi-bundle and use it in Equinox app.
- Create folder "tutorials/MyBundle", create file "build.gradle" in it, insert code:
apply plugin: 'java'
apply plugin: 'osgi-bundle'
- Create folder "tutorials/MyBundle/src/main/java/mybundle", create file "HelloWorld.java" in it, insert code:
package mybundle;
public class HelloWorld {
public static void sayHello() {
System.out.println("Hello, world!");
}
}
- Edit file "tutorials/settings.gradle", insert code:
include 'MyBundle'
so that there are two includes - "MyEquinoxApp" and "MyBundle".
- Edit file "tutorials/MyEquinoxApp/build.gradle", insert code:
dependencies {
compile project(':MyBundle')
}
- Edit file "tutorials/MyEquinoxApp/src/main/java/myequinoxapp/Application.java", replace line containing
System.out.println
withmybundle.HelloWorld.sayHello();
so that the file looks like this:
package myequinoxapp;
import java.io.IOException;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
public class Application implements IApplication {
@Override
public Object start(IApplicationContext ctx) throws Exception {
mybundle.HelloWorld.sayHello();
return IApplication.EXIT_OK;
}
@Override
public void stop() {
// From eclipse doc:
// This method will not be called if an application exits normally from the start(IApplicationContext) method.
}
}
- Invoke on command line in "tutorials" folder:
gradle build
CHECK: folder "tutorials/MyBundle/build/libs" contains file "MyBundle-1.0.0.0.jar", which is proper OSGi bundle with automatically generated manifest.
CHECK: Each product in "tutorials/MyEquinoxApp/build/output" contains "MyBundle" and "MyEquinoxApp" bundles in "plugins" subfolder and in "configuration/config.ini".
CHECK: The product matching your OS/architecture is runnable and prints "Hello, world!" to the console.
The example code corresponding to this page is located in tutorialExamples/EquinoxApp-4.
Now we can move on to create first RCP app.