Versions Compared

Key

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

...

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

The lib/ directory contains the framework Felix' main JAR file, which also contains the OSGi core interfaces. The main JAR file is used so that we can reuse the default launcher's auto-install/auto-start configuration property handling; if these capabilities are needed, then it would be possible to use the framework JAR file. 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 is hung, but it is actually just sitting there waiting for someone to tell it to do something. The src/example/ directory contains the following Main.java file, which is a very simplistic Felix launcher.

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(FelixConstants.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 Nowlist create= an instance of the framework.new ArrayList();
            m_felix = list.add(new Felix(configMap, nullAutoActivator(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 last configuration property, BundleCache.CACHE_PROFILE_DIR_PROP (string value "felix.cache.profiledir"), which is a string that specifies the precise directory to be used as the bundle cache profile directory; the Felix bundle cache supports other properties to configure its behavior, but those are not covered here. In this example, the bundle cache profile directory is specified as a relative directory called "cache". Assuming that the launcher is executed from the root directory of the launcher project, then the bundle cache profile directory will be created in the root directory of the project.

Code Block
            m_felixList list = new FelixArrayList(configMap, null);
            m_felix.start(list.add(new AutoActivator(configProps));

This above creates a list to hold custom framework activators and adds an instance of org.apache.felix.main.AutoActivator to it, which will process the auto-install and auto-start configuration properties during framework startup.

Code Block

            Map configMap = new StringMap(configProps, false);

This above creates a case-insensitive map from the configuration properties, since the OSGi specification says that properties are not case sensitive.

Code Block

            m_felix = new Felix(configMap, list);
            m_felix.start();

These last steps create the framework instance and start it. The configuration property map and custom framework activator list are The last steps create the framework instance and start it. The configuration property map is passed into the Felix constructor.

...

No Format
javac -d . -classpath lib/org.apache.felix.frameworkmain-1.0.02.jar src/example/Main.java

...

No Format
java -cp .:lib/org.apache.felix.frameworkmain-1.0.02.jar example.Main

After executing this command, a cache/ directory is created that contains the installed bundles, which were installed from the bundle/ directory.

...