Apache Felix Framework Usage Documentation

Downloading the Framework

Go to the downloads page and download the latest Felix framework distribution.

Starting the Framework

Start the framework from the installation directory by typing:

java -jar bin/felix.jar

The framework launcher starts the framework and installs a bundles contained in the bundle directory of the current directory. By default, the bundle directory contains a simple text-based shell to interact with the framework. Bundles installed into the framework are copied into a bundle cache directory for subsequent executions. By default, the framework creates a cache directory, called felix-cache, in your current working directory; this behavior is configurable, see the Apache Felix Framework Bundle Cache document for more details.

If you want to start the framework using a different bundle cache directory, you can do so like this:

java -jar bin/felix.jar <cache-path>

Where <cache-path> is the path you want to use as the bundle cache. If you specify a relative cache path, then it will be treated as relative to the current working directory.

Useful Information

Previous versions of the framework prompted for a profile name when executed. The profile name was used to create a directory inside .felix/ in the user home directory. This approach allowed users to have different sets of bundles for different purposes, e.g., testing, production, etc. If this behavior is still desired, it is very easy to mimic. Modify conf/config.properties to include "felix.cache.rootdir=${user.home}/.felix". Now, if you start Felix with something like "java -jar bin/felix.jar foo", it will use "${user.home}/.felix/foo/" as the bundle cache directory, where "${user.home}" is automatically substituted with the appropriate system property by the launcher.

Framework Shell

The main way to interact with the framework is via its shell. Felix' shell is implemented as an OSGi service that, be default, uses a simple text-based user interface. After starting the framework, type help into the shell to see the list of the available commands and help <command-name> to get help for a specific command.

To install bundles, use the install command, which is described in more detail in the next sub-section. To view all currently installed bundles, use the ps command. To stop the framework type stop 0 to stop the System Bundle; any installed bundles will automatically be reloaded (and potentially restarted) the next time you launch with the associated cache.

Installing Bundles

A bundle is the OSGi term for a component for the OSGi framework. A bundle is simply a JAR file containing a manifest and some combination of Java classes, embedded JAR files, native code, and resources. A bundle may provide some specific functionality for the user or it may implement a service that other bundles can use; bundles can only use functionality from other bundles through shared services and packages.

The Felix framework is packaged with three bundles, which are located in the bundle/ directory of the framework installation directory. There are bundles for the Felix shell service, a text-based shell service user interface, and a bundle repository service. In addition to these bundles, the bundle repository services provides access to other bundles for easy installation. The bundle repository service provides a shell command, named obr, to access available bundles; refer to the Apache Felix OSGi Bundle Repository for more information.

Before installing any bundles, it is important to understand how bundles are manually deployed into the framework. Bundles are deployed in two stages; first they are installed, then they are started. To install a bundle use the install shell command followed by a bundle URL. For example, to install a bundle.jar bundle you type (assuming you have started Felix from its installation directory):

install file:/path/to/bundle/bundle.jar

Once a bundle is installed, it can then be started by using the start command and the bundle identifier of the desired bundle. The ps shell command is used to list all installed bundles and to obtain the bundle's identifier. The following Felix shell session capture illustrates how to start the bundle.jar bundle:

-> install [file:bundle/simple]
-> ps
   ID   State         Level  Name
[   0] [Active     ] [    0] System Bundle (2.0.0)
[   1] [Active     ] [    1] Shell Service (1.4.0)
[   2] [Active     ] [    1] Shell TUI (1.4.0)
[   3] [Active     ] [    1] Bundle Repository (1.4.0)
[   4] [Installed  ] [    1] Bundle Example (1.0.0)
-> start 4
Hello from Bundle 4.

The stop command is used to stop a bundle and the uninstall command is used to remove a bundle from the bundle cache. As an alternative to using the install and start commands explicitly, it is also possible to install and start a bundle in one step by using the start command with a bundle URL.

Bundles can be updated using the update command. The update command allows you to specify an URL from which to retrieve the updated bundle, but if one is not specified it will try to update the bundle from the bundle's Bundle-UpdateLocation manifest attribute, if present, or the bundle's original location URL.

Important: When you update or uninstall a bundle, the changes appear to take effect immediately, but in reality the changes are only partially enacted. If a bundle is updated or uninstalled and it was exporting packages, these packages are not removed until the framework is refreshed using the PackageAdmin service. The Felix shell offers a convenient refresh command for this purpose.

For an introduction to writing bundles and services, refer to the Felix bundle tutorial.

Web Proxy Issues when Installing Bundles

If you use a proxy for Web access, then you may run into difficulty using the Felix shell to install bundles from a remote URL. To remedy this situation, certain system properties must be set to make Felix work with your proxy. These properties are:

These system properties can be set directly on the command line when starting the JVM using the standard "-D<prop>=<value>" syntax or you can put them in the lib/system.properties file of your Felix installation; see the next section on configuring Felix for more information.

Bundle Auto-Deploy

To minimize the amount of configuration necessary to install bundles when you launch the framework, the Felix launcher uses the concept of an "auto-deploy" directory. The Felix launcher deploys all bundles in the auto-deploy directory into the framework instance during startup. By default, the auto-deploy directory is "bundle" in the current directory, but it can be specified on the command line like this:

java -jar bin/felix.jar -b /path/to/dir

Specifying an auto-deploy directory replaces the default directory, it does not augment it. The default deployment actions performed on the bundles in the auto-deploy directory are: install, update, and start. Both the location of the auto-deploy directory and the deployment actions performed can be controlled by the following configuration properties, respectively:

The next section describes how to set and use configuration properties.

Configuring the Framework

Both the Felix framework and the launcher use configuration properties to alter their default behavior. The framework can only be configured by passing properties into its constructor, but the launcher provides a mechanism to configure the framework via a property file. The launcher The Felix framework uses properties to configure certain aspects of its behavior. The framework launcher reads configuration properties from conf/config.properties. This file uses standard Java property file syntax.

The launcher also supports setting system properties via the conf/system.properties file. This file is purely for convenience when you need to repeatedly set system properties when running the framework. While the framework itself does not look at system properties, the launcher does copy any framework configuration properties found in the system properties into the framework configuration map, also for your convenience.

It is possible to specify a different locations for these property files for the system properties file by using the felix.config.properties and felix.system.properties system properties when executing the framework. For example:

java -Dfelix.config.properties=file:/home/rickhall/config.properties -jar bin/felix.jar

Configuration and system properties are accessible at run time via BundleContext.getProperty(), but configuration properties override system properties.

The following configuration properties are specifically for the launcher:

The following configuration properties are specifically for the framework (properties starting with "felix" are specific to Felix, while those starting with "org.osgi" are standard OSGi properties):

The Felix framework installation contains a default conf/config.properties file for automatically starting the shell-related bundles.

Migrating from Earlier Versions

Apache Felix Framework 1.4.0 introduced some configuration property changes. This section describes the differences from older versions of the framework.

For the most part, these changes are minor and previous behavior achieved from older configuration properties is either easily attained with the new properties or no longer necessary.

System Property Substituion

It is possible to use system properties to specify the values of properties in the conf/config.properties file. This is achieved through system property substitution, which is instigated by using ${<property>} syntax, where <property> is the name of a system property to substitute. When such a property value is retrieved by a bundle, the system property value will be substituted into the bundle property value as appropriate. It is possible to have nested system property substitution, in which case the inner-most property is substituted first, then the next inner most, until reaching the outer most.

Configuring Bundles

Some bundles use properties to configure certain aspects of their behavior. As an example, the default URL for the cd command of the shell service can be specified using the property felix.shell.baseurl. It is a good idea, when implementing bundles, to parameterize them with properties where appropriate. To learn about the configuration options for specific bundles, refer to the documentation that accompanies them.

Bundle properties are also defined in the conf/config.properties property file. Any property placed in this file will be accessible via BundleContext.getProperty() at run time. The property file uses the standard Java property file syntax (i.e., attribute-value pairs). For information on changing the default location of this file, refer to the section on configuring Felix.


Subscribe to the Felix users mailing list by sending a message to users-subscribe@felix.apache.org; after subscribing, email questions or feedback to users@felix.apache.org.