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.