Meaning:Directly use the editor to edit required osgi services, which is fast and efficient.
Osgi container: Select knopflerfish_osgi_5.1.0 (http://www.knopflerfish.org/) to support osgi's latest R5 standard.
Method:
1. Compile the activator. Java file in the current directory.(You do not need to create the corresponding package folder-save time), The content is as follows (Refer to the tutorial of Felix.)
Package tutorial. example1; import Org. osgi. framework. bundleactivator; import Org. osgi. framework. bundlecontext; import Org. osgi. framework. servicelistener; import Org. osgi. framework. serviceevent;/*** this class implements a simple bundle that utilizes the osgi * framework's event mechanic to listen for service events. upon * processing ing a service event, it prints out the event's details. **/public class activator implements bundleactivator, servicelistener {/*** implements bundleactivator. start (). prints * a message and adds itself to the bundle context as a Service * listener. * @ Param context the framework context for the bundle. **/Public void start (bundlecontext context) {system. out. println ("starting to listen for service events. "); context. addservicelistener (this);}/*** implements bundleactivator. stop (). prints * a message and removes itself from the bundle context as a * service listener. * @ Param context the framework context for the bundle. **/Public void stop (bundlecontext context) {context. removeservicelistener (this); system. out. println ("stopped listening for service events. "); // Note: It is not required that we remove the listener here, // since the Framework will do it automatically anyway .} /*** implements servicelistener. servicechanged (). * prints the details of any service event from the framework. * @ Param event the fired service event. **/Public void servicechanged (serviceevent event) {string [] objectclass = (string []) event. getservicereference (). getproperty ("objectclass"); If (event. getType () = serviceevent. registered) {system. out. println ("ex1: Service of type" + objectclass [0] + "registered. ");} else if (event. getType () = serviceevent. unregistering) {system. out. println ("ex1: Service of type" + objectclass [0] + "unregistered. ");} else if (event. getType () = serviceevent. modified) {system. out. println ("ex1: Service of type" + objectclass [0] + "modified. ");}}}
2. Compile the manifest. MF File
Manifest-version: 2.0bundle-Name: Service listener example -- Description, used to view the title of the bundle.) bundle-description: A bundle that displays messages at startup and when service events occur -- bundle brief description bundle-vendor: knopflerfishbundle-version: 1.0.0bundle-Activator: tutorial. example1.activator -- complete class name. Do not write the import-package: Org. osgi. framework
3. Compile the build. Sh File , Content:
RM *. jarmkdir classesjavac-D classes-CP ~ /Knopflerfish_osgi_5.1.0/osgi/framework. jar *. javajar CFM hello. Jar manifest. mf-C./classes tutorial/example1
(Compile the build. BAT file in windows and modify the content accordingly)
Note:
In the jar command line, hello. the basic name of the JAR file is random ;. there is a space between/classes and tutorial/example1, indicating that the class files under the tutorial/example1 package are compressed into the package under the classes directory.
4. Run the knopflerfish container
Cd ~ /Knopflerfish_osgi_5.1.0/osgi
Java-jar./framework. Jar
Then, drag hello. jar in the preceding three steps into the bundle area of the window, OK.
Advantages of the method described: full command line development is agile without the need for third-party tools.
Fast and manual development of osgi applications