Apache Felix is one of the implementation for OSGi framework. We can download implementation and it will provides the OSGi container to provide runtime environment for OSGi bundles. We can develop bundles and install, start in Apache Felix OSGi container. These bundles should follow the OSGi specification then only it can be deployed into OSGi container such as the implementation provided by Apache Felix.
Liferay 7 have used Apache Felix implementation to support modularity application development while developing Liferay 7 Applications.
Perquisite:
Need to install Java 1.7 or Java 1.8 in your machine. Java 1.8 is recommended.
Working with Apache Felix
Download Apache Felix
Directories Information:
Start Apache Felix
Install and Start OSGi bundles.
Download Apache Felix
Apache Felix implementation can be download from following location.
You can download binary distribution that is zip or tar.gz and it based on your operating system.
Once you downloaded the Apache Felix binary distribution then you can extract it in any of your local directory.
You can see the following directories once you extracted the zip or tar file.
Directories Information
bin
This directory contained actual OSGi implementation jar file (felix.jar).
Another directory called felix-cache this will provide cache for bundles and its default directory and we can change cache folder from properties file.
bundle
Bundle directory is auto deployment directory for OSGi container. Bundles which are deployed in this directly automatically started and running when OSGi container started.
Whenever the bundles are mandatory and that should needed for our environment then we can place these OSGi bundles in bundle directory so that it will be started and running automatically by OSGi container when it launched.
Apache Felix is providing the Command Line Interface (CLI) to manage or handle bundles and this implementation called Apache GoGo Shell. These bundles should start along with OSGi container that is why these bundles are placed in bundle directory.
conf
Conf directory contains configuration properties that should needed for OSGi container.
We have file called config.properties and it will contains all the required properties. We have list of properties that can be available to configure and all are listed in the document apache-felix-framework-configuration-properties and it’s available in doc directory.
doc
Doc directory contains all documents about Apache Felix and there are html pages you can directly open and read the documentations.
Start Apache Felix
Open command prompt and navigate Apache Felix home directory from there run the following command then Apache Felix will launch
java –jar bin/felix.jar |
Once it started you can see Apache GoGo Shell command line interface from there we can manage bundles life-cycle.
Note:
Apache GoGoalready available in default deployment directory that is why when you launch Apache Felix then Apache GoGo bundles also started then it will be available for use.
Once Apache Felix stated then you can see Apache GoGo shell command as follows
Type helpcommand in the GoGo shell then we can see list of commands available.
Type lb or felix:lb command it list the available bundles in the OSGi container and shows its states(Active, Installed, DeActive)
Install and Start OSGi bundles.
Once we developed the OSGi bundle by following the framework specification then we can deploy these bundles into OSGi container.
We can start bundle and stop bundle using Apache GoGo shell command with commands.
First need to install bundle then start the bundle. We can install bundle from any location by proving bundle path.
The following is the way to install, start and stop bundles.
Install Bundle
install file:/path/to/bundle/bundle.jar OR felix:install file:/path/to/bundle/bundle.jar |
List Bundles
lb OR felix:lb |
Start Bundle
start bundle-id-in-list OR felix:start bundle-id-in-list |
Stop Bundle
stop bundle-id-in-list OR felix:stop bundle-id-in-list |
The following is screen to shows the bundle life-cycle
Note:
OSGi bundle is packaged jar file.
Apache Felix used default port 8080 for http service and to change this port we have property in config.properties file.
org.osgi.service.http.port=8080 |
Reference:
Author
0 comments:
Post a Comment