-
Notifications
You must be signed in to change notification settings - Fork 51
Create OSGi bundle and use it in Equinox app
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: 'org.akhikhl.wuff.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.println
with mybundle.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" must contain file "MyBundle-1.0.0.0.jar", which is proper OSGi bundle with automatically generated manifest.
Check: each product in "tutorials/MyEquinoxApp/build/output" must contain "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: examples/EquinoxApp-4.
We are done with building Equinox app. Now we can go back to wiki home page and learn something else.