Fast and manual development of osgi applications

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.