Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This section creates a bare-bones launcher to demonstrate the minimum requirements for creating an interactive launcher for the Felix framework. This example uses the standard Felix shell bundles for interactivity, but any other bundles could be used tooinstead. For example, the shell service and telnet bundles could be used to lauch Felix and make it remotely accessible.

This example launcher has the following directory structure:

No Format
bundlelib/
   org.apache.felix.shellframework-0.8.0-SNAPSHOT.jar
   org.apache.felix.shell.tuiosgi.core-0.8.0-SNAPSHOT.jar
libbundle/
   org.apache.felix.frameworkshell-0.8.0-SNAPSHOT.jar
   org.osgi.coreapache.felix.shell.tui-0.8.0-SNAPSHOT.jar
src/
   example/
      Main.java

The lib/ directory contains the JAR files for the framework as well as the OSGi interfaces. The bundle/ directory contains the shell service and textual shell interface bundles that will be used for interacting with the framework instance. Note: If you do not launch Felix with interactive bundles, it will appear as if the framework instance hangs, but it is actually just sitting there waiting for someone to tell it to do something. The {[src/example/}} contains the following Main.java file, which is a very simplistic Felix launcher.

Code Block
package example;

import java.util.Map;
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.cache.BundleCache;
import org.apache.felix.framework.util.MutablePropertyResolverImpl;
import org.apache.felix.framework.util.StringMap;
import org.apache.felix.framework.util.FelixConstants;

public class Main
{
    private static Felix m_felix = null;

    public static void main(String[] argv) throws Exception
    {
        // Print welcome banner.
        System.out.println("\nWelcome to Felix.");
        System.out.println("=================\n");

        Map configMap = new StringMap(false);
        configMap.put(FelixConstants.FRAMEWORK_SYSTEMPACKAGES,
            "org.osgi.framework; version=1.3.0," +
            "org.osgi.service.packageadmin; version=1.2.0," +
            "org.osgi.service.startlevel; version=1.0.0," +
            "org.osgi.service.url; version=1.0.0");
        configMap.put(FelixConstants.AUTO_START_PROP + ".1",
            "file:bundle/org.apache.felix.shell-0.8.0-SNAPSHOT.jar " +
            "file:bundle/org.apache.felix.shell.tui-0.8.0-SNAPSHOT.jar");
        configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "cache");

        try
        {
            // Now create an instance of the framework.
            m_felix = new Felix();
            m_felix.start(
                new MutablePropertyResolverImpl(configMap),
                null);
        }
        catch (Exception ex)
        {
            System.err.println("Could not create framework: " + ex);
            ex.printStackTrace();
            System.exit(-1);
        }
    }
}

...