How to Create a Command for Apache Karaf

1) Create the command class:

package br.eti.fernandoribeiro.sample;

import org.apache.felix.gogo.commands.Command;

@Command(scope = "simplesassim", name = "sample")
public final class SampleCommand extends OsgiCommandSupport {

  protected Object doExecute() {
    return null;


2) Create the sample.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  <command-bundle xmlns="">
    <command name="simplesassim/sample"> <!-- As per KARAF-1001, this will be only a bean ID in 3.0 -->
      <action class="br.eti.fernandoribeiro.sample.SampleCommand" />

3) Build the bundle.

4) Install the bundle.

5) Run the command:


A sample is available here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s