8.2. Deploying a Feature

Overview

You can deploy a feature in one of the following ways:
  • Install at the console, using features:install.
  • Use hot deployment.
  • Modify the boot configuration (first boot only!).

Installing at the console

After you have created a feature (by adding an entry for it in a feature repository and registering the feature repository), it is relatively easy to deploy the feature using the features:install console command. For example, to deploy the example-camel-bundle feature, enter the following pair of console commands:
JBossFuse:karaf@root> features:refreshUrl
JBossFuse:karaf@root> features:install example-camel-bundle
It is recommended that you invoke the features:refreshUrl command before calling features:install, in case any recent changes were made to the features in the feature repository which the kernel has not picked up yet. The features:install command takes the feature name as its argument (and, optionally, the feature version as its second argument).
Note
Features use a flat namespace. So when naming your features, be careful to avoid name clashes with existing features.

Uninstalling at the console

To uninstall a feature, invoke the features:uninstall command as follows:
JBossFuse:karaf@root> features:uninstall example-camel-bundle
Note
After uninstalling, the feature will still be visible when you invoke features:list, but its status will now be flagged as [uninstalled].

Hot deployment

You can hot deploy all of the features in a feature repository simply by copying the feature repository file into the InstallDir/deploy directory.
As it is unlikely that you would want to hot deploy an entire feature repository at once, it is often more convenient to define a reduced feature repository or feature descriptor, which references only those features you want to deploy. The feature descriptor has exactly the same syntax as a feature repository, but it is written in a different style. The difference is that a feature descriptor consists only of references to existing features from a feature repository.
For example, you could define a feature descriptor to load the example-camel-bundle feature as follows:
<?xml version="1.0" encoding="UTF-8"?>
<features name="CustomDescriptor">
  <repository>RepositoryURL</repository>
  <feature name="hot-example-camel-bundle">
    <feature>example-camel-bundle</feature>
  </feature>
</features>
The repository element specifies the location of the custom feature repository, RepositoryURL (where you can use any of the URL formats described in Appendix A, URL Handlers). The feature, hot-example-camel-bundle, is just a reference to the existing feature, example-camel-bundle.

Hot undeploying a features file

To undeploy a features file from the hot deploy directory, simply delete the features file from the InstallDir/deploy directory while the Apache Karaf container is running.
Important
The hot undeploy mechanism does not work while the container is shut down. If you shut down the Karaf container, delete the features file from deploy/, and then restart the Karaf container, the features will not be undeployed after you restart the container (you can, however, undeploy the features manually using the features:uninstall console command).

Adding a feature to the boot configuration

If you want to provision copies of Apache Karaf for deployment on multiple hosts, you might be interested in adding a feature to the boot configuration, which determines the collection of features that are installed when Apache Karaf boots up for the very first time.
The configuration file, /etc/org.apache.karaf.features.cfg, in your install directory contains the following settings:
...
#
# Comma separated list of features repositories to register by default
#
featuresRepositories=\
        mvn:org.apache.karaf.assemblies.features/standard/2.4.0.redhat-630187/xml/features,\
        mvn:org.apache.karaf.assemblies.features/spring/2.4.0.redhat-630187/xml/features,\
        mvn:org.apache.karaf.assemblies.features/enterprise/2.4.0.redhat-630187/xml/features,\
        mvn:org.apache.cxf.karaf/apache-cxf/3.1.5.redhat-630187/xml/features,\
        mvn:org.apache.camel.karaf/apache-camel/2.17.0.redhat-630187/xml/features,\
        mvn:org.apache.activemq/activemq-karaf/5.11.0.redhat-630187/xml/features-core,\
        mvn:io.fabric8/fabric8-karaf/1.2.0.redhat-630187/xml/features,\
        mvn:org.jboss.fuse/jboss-fuse/6.3.0.redhat-187/xml/features,\
        mvn:io.fabric8.patch/patch-features/1.2.0.redhat-630187/xml/features,\
        mvn:io.hawt/hawtio-karaf/1.4.0.redhat-630187/xml/features,\
        mvn:io.fabric8.support/support-features/1.2.0.redhat-630187/xml/features,\
        mvn:org.fusesource/camel-sap/6.3.0.redhat-187/xml/features,\
        mvn:org.switchyard.karaf/switchyard/2.1.0.redhat-630187/xml/core-features

#
# Comma separated list of features to install at startup
#
featuresBoot=\
        jasypt-encryption,\
        pax-url-classpath,\
        deployer,\
        config,\
        management,\
        fabric-cxf,\
        fabric,\
        fabric-maven-proxy,\
        patch,\
        transaction,\
        jms-spec;version=2.0,\
        mq-fabric,\
        swagger,\
        camel,\
        camel-cxf,\
        camel-jms,\
        camel-amq,\
        camel-blueprint,\
        camel-csv,\
        camel-ftp,\
        camel-bindy,\
        camel-jdbc,\
        camel-exec,\
        camel-jasypt,\
        camel-saxon,\
        camel-snmp,\
        camel-ognl,\
        camel-routebox,\
        camel-script,\
        camel-spring-javaconfig,\
        camel-jaxb,\
        camel-jmx,\
        camel-mail,\
        camel-paxlogging,\
        camel-rmi,\
        war,\
        fabric-redirect,\
        hawtio-offline,\
        support,\
        hawtio-redhat-fuse-branding,\
        jsr-311

featuresBlackList=\
        pax-cdi-openwebbeans,\
        pax-cdi-web-openwebbeans,\
        spring-struts,\
        cxf-bean-validation-java6,\
        pax-cdi-1.2-web,\
        pax-jsf-support,\
        camel-ignite,\
        camel-jetty8,\
        camel-ironmq,\
        camel-gae
This configuration file has two properties:
  • featuresRepositories—comma separated list of feature repositories to load at startup.
  • featuresBoot—comma separated list of features to install at startup.
  • featuresBlackList—comma separated list of features that are prevented from being installed (to protect against unsupported or buggy features).
You can modify the configuration to customize the features that are installed as JBoss Fuse starts up. You can also modify this configuration file, if you plan to distribute JBoss Fuse with pre-installed features.
Important
This method of adding a feature is only effective the first time a particular Apache Karaf instance boots up. Any changes made subsequently to the featuresRepositories setting and the featuresBoot setting are ignored, even if you restart the container.
You could force the container to revert back to its initial state, however, by deleting the complete contents of the InstallDir/data/cache (thereby losing all of the container's custom settings).