Example #1
1
  @SuppressWarnings("unchecked")
  public void init() {
    Map config = new HashMap();
    List list = new ArrayList();

    File pluginDir = Main.pref.getPluginsDirectory();
    pluginDirName = pluginDir.getAbsolutePath() + "/";

    list.add(this);
    // config.put(AutoProcessor.AUTO_START_PROP + ".1",
    //		"file:" + pluginDirName + "/bundle/de.vogella.felix.firstbundle_1.0.0.201010271606.jar");
    config.put(BundleCache.CACHE_ROOTDIR_PROP, pluginDirName);
    config.put(Constants.FRAMEWORK_STORAGE_CLEAN, "onFirstInit");
    config.put(FelixConstants.LOG_LEVEL_PROP, "4");
    config.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);

    // Now create an instance of the framework with
    // our configurations properties
    felix = new Felix(config);

    // now start Felix instance
    try {
      felix.start();
    } catch (BundleException e) {
      System.err.println("Could not generate framework: " + e);
      e.printStackTrace();
    }
  }
Example #2
1
  /**
   * Enables the bundle to run as a stand-alone application. When this static <tt>main()</tt> method
   * is invoked, the application creates its own embedded Felix framework instance and interacts
   * with the internal services to provide drawing functionality. To successfully launch as a
   * stand-alone application, this method should be invoked from the bundle's installation directory
   * using "<tt>java -jar</tt>".
   *
   * @param argv The command-line arguments.
   * @throws Exception If anything goes wrong.
   */
  public static void main(String[] argv) throws Exception {
    // Create a temporary bundle cache directory and
    // make sure to clean it up on exit.
    final File cachedir = File.createTempFile("felix.example.servicebased", null);
    cachedir.delete();
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              public void run() {
                deleteFileOrDir(cachedir);
              }
            });

    Map configMap = new StringMap(false);
    configMap.put(
        Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
        "org.apache.felix.example.servicebased.host.service; version=1.0.0");
    configMap.put(
        AutoActivator.AUTO_START_PROP + ".1",
        "file:../servicebased.circle/target/servicebased.circle-1.0.0.jar "
            + "file:../servicebased.square/target/servicebased.square-1.0.0.jar "
            + "file:../servicebased.triangle/target/servicebased.triangle-1.0.0.jar");
    configMap.put(FelixConstants.LOG_LEVEL_PROP, "4");
    configMap.put(Constants.FRAMEWORK_STORAGE, cachedir.getAbsolutePath());

    // Create list to hold custom framework activators.
    List list = new ArrayList();
    // Add activator to process auto-start/install properties.
    list.add(new AutoActivator(configMap));
    // Add our own activator.
    list.add(new Activator());
    // Add our custom framework activators to the configuration map.
    configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);

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