Hi, 

I am a newbie to karaf, and I am trying to figure out how to embed it in
another program. My understanding is that something like the following code
should work (taken from
http://njbartlett.name/2011/03/07/embedding-osgi.html):

FrameworkFactory frameworkFactory =
ServiceLoader.load(FrameworkFactory.class).iterator().next(); 
Map<String, String> config = new HashMap<String, String>(); 
// TODO: add some config properties 
Framework framework = frameworkFactory.newFramework(config); 
framework.start(); 

Should this work for karaf? And if so what jar files need to be included to
obtain the framework factory as in above? 

On the other hand, the karaf Main (2.3.1) does something different: 

        String factoryClass =
configProps.getProperty(KARAF_FRAMEWORK_FACTORY); 
        if (factoryClass == null) { 
            InputStream is =
classLoader.getResourceAsStream("META-INF/services/" +
FrameworkFactory.class.getName()); 
            BufferedReader br = new BufferedReader(new InputStreamReader(is,
"UTF-8")); 
            factoryClass = br.readLine(); 
            br.close(); 
        } 
        FrameworkFactory factory = (FrameworkFactory)
classLoader.loadClass(factoryClass).newInstance(); 
        framework = factory.newFramework(new StringMap(configProps, false)); 

Would this be the correct way of embedding karaf? If so, what jar file
should include the FrameworkFactory services resource, and what jar file
should include the actual factoryClass implementation? 

Thanks in advance for any help in clarifying the right way to embed karaf. 

Azad




--
View this message in context: 
http://karaf.922171.n3.nabble.com/embedding-karaf-tp4028257.html
Sent from the Karaf - User mailing list archive at Nabble.com.

Reply via email to