Thursday, 25 June 2015

OSGi 101 - Apache Felix - Gogo console

This short tutorial will show you step by step how to run Apache Felix OSGi console and explore few of the supported commands.

Step 1 - Download and extract the Felix Framework Distribution. At this moment the current version is 5.0.1 and the folder structure looks like this:

Apache Felix 5.0.1 - Folder Structure
Apache Felix 5.0.1 - Folder Structure


Step 2 - Open console window and navigate to the folder where you just unpacked the OSGi framework.

Step 3 - Execute the following command (Windows style):

java -jar .\bin\felix.jar

You should see the following result:

Apache Felix 5.0.1 - Gogo Console
Apache Felix 5.0.1 - Gogo Console
Well, that's it! If you see g! it means that you have accessed the OSGi console and now you can perform OSGi operations! Let's see what we can do!

First of all you'd like to try the help command:

Apache Felix 5.0.1 - Gogo Help
Apache Felix 5.0.1 - Gogo Help
You can use both the full command name, e.g. felix:help or just the short version, e.g. help. The same applies for the command lb (stands for "list bundles") which can also be executed as felix:lb. The default output is this:

Apache Felix 5.0.1 - ("felix:lb" or "lb")
Apache Felix 5.0.1 - ("felix:lb" or "lb")
There are currently 5 available OSGi bundles with ID's form 0 to 4. When you create your own OSGi bundle and install it, your bundle will have its own ID. I'll write another article and explain how to develop a very simple OSGi bundle, how to install it, start it and stop it properly.

Here are some of the commands you can use:

help <command> - displays information about a specific command.
Example:
help headers

install <url> - installs new OSGi bundle.
Example:
install file:path/to/my-osgi-bundle.jar

start <id> - starts already installed and fully resolved OSGi bundle.
Example:
start 1

stop <id> - stops running OSGi bundle.
Example:
stop 0

The last command will end the Gogo session since we are stopping the OSGi application with ID=0 which is the system bundle and we are effectively stopping the whole OSGi engine. You can try to stop the "Gogo Shell" bundle with ID=4 and then start it again. See for yourself what's the result. You'll need to restart the OSGi engine in order to restore the functionality of the shell.

OK, that's all. This is not supposed to be a full OSGi tutorial - it's just a fast way to start with Apache Felix. In my next post I'll concentrate on developing a very simple OSGi bundle and how to make it run in Apache Felix. It'll be fun! :)

No comments:

Post a Comment