WSO2 Carbon Feature manager is powered by Equinox P2. Equinox is a very popular, widely used implementation of the OSGi framework. The command line console of Equinox can be accessed by running with the “-console” option.
You can run the equinox jar file with the console enabled as follows.
java -jar org.eclipse.osgi_3.9.1.v20140110-1610.jar -console
Also you can access the OSGi console of your Eclipse installation. Go to the folder where Eclipse is installed and run the following command.
As usual, “help” command in the prompt will give a list of available commands and what they do.
The most interesting commands for getting started are:
- install <bundle URL> – Installs the bundle from the given URL
- start <bundle # or bundle name> – Starts the bundle with the given numeric or symbolic id
- stop <bundle # or bundle name> – Stops the bundle with the given numeric or symbolic id
- ss – Reports a summary status of all installed bundles
- diag <bundle # or bundle name> – Reports any resolution problems for the bundle with the given numeric or symbolic id
The Equinox OSGi implementation can be configured. One of the most common configuration scenarios is to have the framework automatically install and run a set of bundles when it is started. You can do this by editing ‘config.ini’ file.
If you have bundles A.jar and B.jar that you want to have installed and started when Equinox is run. As with other OSGi implementations, you can run the framework (with java -jar ) and install and start A and B using the console. This is a manual process but you need only do it the first time you run Equinox (OSGi frameworks remember the installed and started bundles from run to run). To do something completely automated, create a configuration that lists A and B as bundles to be installed and started. You can use some thing similer design as following structure.
Where config.ini is a Java properties file that contains the following line.
When Equinox is started using the command line above, A and B are installed and started.
Also the CommandProvider interface provided by Equinox enables to extend the console by providing custom commands. We need to implement the CommandProvider interface. For each new command we add, we need to provide ‘public void’ methods which take in a CommandInterpreter object. Also the method names should start with an underscore and should be followed by the command name. The getHelp() method should return a string describing the commands we add, so that it can be displayed through the help command.