1. Write the Java file that inherits bundleactivator. The start () function is the entry to the osgi platform call start.
Package com. javaworld. sample. helloworld;
Import org. osgi. Framework. bundleactivator;
Import org. osgi. Framework. bundlecontext;
Public class activator implements bundleactivator {
/*
* (Non-javadoc)
* @ See org. osgi. Framework. bundleactivator # Start (Org. osgi. Framework. bundlecontext)
*/
Public void start (bundlecontext context) throws exception {
System. Out. println ("Hello world !! ");
}
/*
* (Non-javadoc)
* @ See org. osgi. Framework. bundleactivator # Stop (Org. osgi. Framework. bundlecontext)
*/
Public void stop (bundlecontext context) throws exception {
System. Out. println ("Goodbye World !! ");
}
}
2. Create a new directory and test the org. Eclipse. osgi_3.5.1.r35x_v20090827.jar (osgi package of eclipse) and Java file under this directory. Go to the directory and compile and modify the class.
Javac-classpath org. Eclipse. osgi_3.5.1.r35x_v20090827.jar COM/javaworld/sample/helloworld/Activator. Java
3. Create a manifest. MF file in the META-INF directory, specify bundle-activator and other settings.
Manifest-version: 1.0
Bundle-vendor: javaworld
Bundle-version: 1.0.0.qualifier
Bundle-Name: helloworld
Created-by: 1.6.0 _ 14 (Sun Microsystems Inc .)
Bundle-Activator: COM. javaworld. sample. helloworld. Activator
Bundle-manifestversion: 2
Import-package: org. osgi. Framework; version = "1.3.0"
Bundle-symbolicname: COM. javaworld. sample. helloworld
4. Package
Jar-CFM com. javaworld. sample. helloworld. activator. Jar helloworld. mf com/javaworld/sample/helloworld/Activator. Class
5. Enter the directory at the DOS prompt and start osgi
Java-jar org. Eclipse. osgi_3.5.1.r35x_v20090827.jar-Console
6. Install and create a bundle
Osgi> Install file: COM. javaworld. sample. helloworld. activator. Jar
7. Start bundle according to the ID. If the ID is 1
Osgi> Start 1
8. Stop bundle
Osgi> stop 1
9. Uninstall bundle
Osgi> uninstall file: COM. javaworld. sample. helloworld. activator. Jar