Helloworld_osgi of OSGI

Source: Internet
Author: User

The main function of the HelloWorld example program is to do something (output information) when starting and stopping a bundle.

1. Create bundle Project

(1) Create a plug-in project in eclipse

(2) Input project related information

(3) Enter the relevant metadata information of bundle:

The plug_in ID refers to the unique identification of the bundle, and the Java-like package name organization strategy can be used in the actual project to guarantee the uniqueness of the identity

Plug-in version refers to the versions of bundle

Plug-in name refers to the more meaningful name of Bundlebundle

Plug-in Provider refers to the provider of bundle.

Execution environment refers to the environment that bundle needs to run

The rest of the key is the Activitor section, fill in your own class name on it, when the project is built, eclipse will automatically create this class

(4) After the creation of the bundle project, you can see in the package view the following illustration showing the success of the project creation:

2, complete the Activator code

(1) Open the default Activator.java

This class implements the Bundleactivator interface, which has two empty methods--start and stop. The Start method is invoked when the bundle is started, and the stop is invoked when the bundle is stopped, adding code:

HelloWorld examples are complete.

3, Operation

(1) First create a HelloWorld run configuration

(2) Then set the Helloworldde Auto-start property to False

(3) Click Run and the "osgi>" prompt appears in the console. Indicates that an OSGI application was successfully started.

Enter SS after the osgi> prompt, press ENTER, as shown below:

As you can see, the HelloWorld bundle has been installed and resolved, but has not yet started. Next, enter start 1 at the osgi> prompt, and then enter the SS:

See HelloWorld started, through the SS can see HelloWorld bundle state changed to active, indicating successful start. And the output information added to the Activitor Start method is printed correctly.

Then enter stop 1 and then use the SS command to view the status of the bundle:

This time bundle stop.

At this point, an OSGi bundle is successfully completed and the first OSGi program runs smoothly.

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.