Hi guys,

Thanks for the replies.

At this stage my head still has a couple of hairs left to pull out
:confused:.

My test implementation goes something like this - sorry for the long
explanation, I really tried to make it short :-D

1. I am using eclipse 3.7 with bndtools.
2. My workspace includes 4 OSGI enabled projects:
   a. cnf
   b. org.me.osgi.app1 (starts org.me.osgi.app1.plugincontainer,
org.me.osgi.app1.spi.service, org.me.osgi.app1)
   c. org.me.osgi.app1.spi.service (defines an interface 'ServiceProvider'
as is exported)
   d. org.me.osgi.app1.plugincontainer (launches a new osgi framework and
installs,starts bunbles found in a pre-defined dir)
3. The org.me.osgi.app1.plugincontainer package defines a BundleActivator
which is responsable for launching the new osgi framework

    public final class FrameworkActivator implements BundleActivator {
      private FrameworkFactory frameworkFactory;
      private Framework framework;
      
      @Override
      public void start(BundleContext context) throws Exception {
        Map<String,String> config = new  HashMap<String, String>();
        config.put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, "JavaSE-1.6");
        config.put(Constants.FRAMEWORK_STORAGE_CLEAN,
Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
        config.put(Constants.FRAMEWORK_STORAGE,
"/home/me/tests/osgi/cache");
        config.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"org.me.osgi.app1.spi.service");
        config.put(Constants.FRAMEWORK_BUNDLE_PARENT,
Constants.FRAMEWORK_BUNDLE_PARENT_EXT);
        
        frameworkFactory =
ServiceLoader.load(FrameworkFactory.class).iterator().next();
        framework = frameworkFactory.newFramework(config);
        
        framework.init();
        framework.start();
        
        File deployDirectory = new File("/home/me/tests/osgi/deploy");
        File[] jars = deployDirectory.listFiles(new FileFilter() {
          @Override
          public boolean accept(File file) {
            if(null != file && file.exists() && file.isFile() &&
file.getName().endsWith(".jar")) {
              return true;
            }
            return false;
          }
        });
        
        List<Bundle> installedBundles = new LinkedList<Bundle>();
        for(File jar: jars) {
         
installedBundles.add(framework.getBundleContext().installBundle("file:" +
jar.getAbsolutePath()));
        }
        
        for (Bundle bundle : installedBundles) {
          if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
            bundle.start();
          }
        }
      }
      
      @Override
      public void stop(BundleContext context) throws Exception {
        framework.stop();
        framework.waitForStop(0);
      }
    }

4. The /home/me/tests/osgi/deploy directory contains the following bundles:
    osgi.cmpn-4.2.1.jar
    org.apache.felix.scr-1.4.0.jar
    org.apache.felix.shell-1.4.2.jar
    org.apache.felix.shell.tui-1.4.1.jar
    org.me.osgi.app1.plugincontainer.extension-1.0.0.jar
    org.me.osgi.app1.plugins.greetingservice-1.0.0.jar
    
5 The MANIFEST.MF for fragment bundle
org.me.osgi.app1.plugincontainer.extension-1.0.0.jar contains the following
headers
    Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: org.me.osgi.app1.plugincontainer.extension
    Bundle-SymbolicName: org.me.osgi.app1.plugincontainer.extension
    Bundle-Version: 1.0.0
    Bundle-RequiredExecutionEnvironment: JavaSE-1.6
    Fragment-Host: system.bundle; extension:=framework
    Export-Package: org.me.osgi.app1.spi.service;version="1.0.0"

6. Launching the outer framework (via eclipse) I get the following error:
    Failed to start bundle org.me.osgi.app1.plugincontainer-1.0.0, exception
Activator start error in bundle org.me.osgi.app1.plugins.greetingservice
[6].
    
7. -> ps (inner framework)
START LEVEL 1
   ID   State         Level  Name
[   0] [Active     ] [    0] System Bundle (3.0.4)
[   1] [Active     ] [    1] Apache Felix Declarative Services (1.4.0)
[   2] [Active     ] [    1] Apache Felix Shell Service (1.4.2)
[   3] [Active     ] [    1] Apache Felix Shell TUI (1.4.1)
[   4] [Active     ] [    1] osgi.cmpn (4.2.1.201001051203)
[   5] [Resolved   ] [    1] org.me.osgi.app1.plugincontainer.extension
(1.0.0)
[   6] [Resolved   ] [    1] org.me.osgi.app1.plugins.greetingservice
(1.0.0)

8. -> start 6
org.osgi.framework.BundleException: Activator start error in bundle
org.me.osgi.app1.plugins.greetingservice [6].
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1869)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1739)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:922)
        at
org.apache.felix.shell.impl.StartCommandImpl.execute(StartCommandImpl.java:114)
        at
org.apache.felix.shell.impl.Activator$ShellServiceImpl.executeCommand(Activator.java:286)
        at
org.apache.felix.shell.tui.Activator$ShellTuiRunnable.run(Activator.java:184)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError:
org/me/osgi/app1/spi/service/ServiceProvider
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at
org.apache.felix.framework.ModuleImpl$ModuleClassLoader.findClass(ModuleImpl.java:1872)
        at
org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:720)
        at org.apache.felix.framework.ModuleImpl.access$300(ModuleImpl.java:73)
        at
org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1733)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at
org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:638)
        at 
org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3660)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1817)
        ... 6 more
Caused by: java.lang.ClassNotFoundException:
org.me.osgi.app1.spi.service.ServiceProvider
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at
org.apache.felix.framework.ExtensionManager$ExtensionManagerModule.getClassByDelegation(ExtensionManager.java:692)
        at 
org.apache.felix.framework.resolver.WireImpl.getClass(WireImpl.java:99)
        at
org.apache.felix.framework.ModuleImpl.searchImports(ModuleImpl.java:1370)
        at
org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:715)
        at org.apache.felix.framework.ModuleImpl.access$300(ModuleImpl.java:73)
        at
org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1733)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 17 more
java.lang.NoClassDefFoundError: org/me/osgi/app1/spi/service/ServiceProvider

I have tried other things, but this is how I understand it to be, of which
I'm definitely missing something in my understanding of things.

Thanks Again
Jorge


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

-- 
View this message in context: 
http://old.nabble.com/launch-framework-from-bundle-tp32155585p32160242.html
Sent from the Apache Felix - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to