-
Notifications
You must be signed in to change notification settings - Fork 48
Create OSGi bundle and use it in Equinox app
Andrey Hihlovskiy edited this page Apr 23, 2014
·
32 revisions
We already prepared Equinox app for multiproject build. Now we 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! I am OSGi bundle!");
}
}- 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.printlnwithmybundle.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 buildCHECK: 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".
-
Run the compiled product from command line. The expected output:

The example code for this page: tutorialExamples/EquinoxApp-4.
Now we are done with Equinox tutorial. Other tutorials are available here.