Skip to content

Instantly share code, notes, and snippets.

@rotty3000
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rotty3000/fcd47c42cb0a12141f52 to your computer and use it in GitHub Desktop.
Save rotty3000/fcd47c42cb0a12141f52 to your computer and use it in GitHub Desktop.
embedded framework example to test fileinstall
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.ServiceLoader;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.launch.Framework;
import org.osgi.framework.launch.FrameworkFactory;
public class FIAndEquinoxTest {
public static void main(String[] args) throws Exception {
Map<String, String> p = new HashMap<String, String>();
p.put(
"org.osgi.framework.storage",
System.getProperty("user.home") + File.separator + "osgi");
File deployDir = new File(
System.getProperty("user.home") + File.separator + "osgi-deploydir");
deployDir.mkdirs();
p.put(
"felix.fileinstall.dir",
System.getProperty("user.home") + File.separator + "osgi-deploydir");
ServiceLoader<FrameworkFactory> factories = ServiceLoader.load(
FrameworkFactory.class);
FrameworkFactory factory = factories.iterator().next();
Framework framework = factory.newFramework(p);
framework.init();
BundleContext context = framework.getBundleContext();
Bundle bundle = context.installBundle(
"http://archive.apache.org/dist/felix/org.apache.felix.fileinstall-3.4.0.jar");
bundle.start();
framework.start();
framework.waitForStop(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment