Versions Compared

Key

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

...

Wiki Markup
_\[This document is based on Felix 1.0.23.\]_

...

No Format
launcher/
   lib/
      org.apache.felix.main-1.0.23.jar
   bundle/
      org.apache.felix.shell-1.0.0.jar
      org.apache.felix.shell.tui-1.0.0.jar
   src/
      example/
         Main.java

...

Code Block
package example;

import java.util.Map;
import org.osgi.framework.Constants;
import org.apache.felix.framework.Felix;
import org.apache.felix.framework.cache.BundleCache;
import org.apache.felix.framework.util.StringMap;
import org.apache.felix.framework.util.FelixConstants;
import org.apache.felix.framework.main.AutoActivator;

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(Constants.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(FelixConstantsAutoActivator.AUTO_START_PROP + ".1",
            "file:bundle/org.apache.felix.shell-1.0.0.jar " +
            "file:bundle/org.apache.felix.shell.tui-1.0.0.jar");
        configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "cache");

        try
        {
            List list = new ArrayList();
            list.add(new AutoActivator(configProps));
            Map configMap = new StringMap(configProps, false);
            m_felix = new Felix(configMap, list);
            m_felix.start();
        }
        catch (Exception ex)
        {
            System.err.println("Could not create framework: " + ex);
            ex.printStackTrace();
            System.exit(-1);
        }
    }
}

...

This sets the Constants.FRAMEWORK_SYSTEMPACKAGES configuration property (string value "org.osgi.framework.system.packages"), which specifies the class path packages the system bundle should export; this is how classes on the class path are made available to bundles. This example only exports the core OSGi API packages, but other JRE packages could also be added, such as javax.swing. For example, the default Felix launcher defines properties for all packages in various JRE versions (e.g., 1.3.x, 1.4.x, 1.5.x) and appends them to this property using property substitution.

Code Block
        configMap.put(FelixConstantsAutoActivator.AUTO_START_PROP + ".1",
            "file:bundle/org.apache.felix.shell-1.0.0.jar " +
            "file:bundle/org.apache.felix.shell.tui-1.0.0.jar");

This sets the FelixConstantsAutoActivator.AUTO_START_PROP configuration property (string value "felix.auto.start"), which is a space-delimited list of bundle URLs that the framework will automatically install and start when the framework starts. However, this property key cannot be used as is; it must be appended with a "." and then a number, where the number represents the start level for the bundle when it is installed. In this particular example, ".1" is appended to the property name, thus the two bundles will be installed into start level one. This example uses relative file: URLs, which will load the bundles from the bundle/ directory assuming that the launcher is started from the root directory of the launcher project. It is also possible to specify absolute URLs or remote URLs.

...