Home » Eclipse Projects » Virgo » OSGI bundle dependencies
OSGI bundle dependencies [message #671393] |
Tue, 17 May 2011 17:55 |
rshelley Messages: 59 Registered: April 2010 |
Member |
|
|
I'm having some trouble with OSGI bundle dependencies and I can't tell if it's something wrong with my idea of bundles, or if I'm just not configured properly.
I have two bundles, BundleA (a WAR) and BundleB (a JAR). Both bundles are Maven projects, so BundleB has a compile dependency on BundleA (for the interface).
BundleA defines an interface and exports the package for the interface (I can see the exported package in Virgo).
BundleB imports the package from BundleA and has an implemented service based upon the interface in BundleA.
The goal is to have BundleA define some interfaces it supports, and BundlesB/C/D/... implement those services so they can be registered into BundleA as they are loaded.
However, BundleB gets a ClassNotFoundException for the interface that's defined in BundleA (even though the package is exported from A and imported by B). BundleB can't include the interface's Class files either because it's a JAR and doesn't include other JARs from dependencies.
Am I just not thinking about the bundles correctly, or is something just not configured properly?
My goal is to have a core application that listens for specific services to come and go. When they are loaded, I want to add those services to a list of active services the core application can work with, and I want those services to be well defined by the core application (so if a UserLookupService is registered, the core application knows what methods can be called on it).
Should the interface come from the service being registered, or should it come from my core application that defines the scope of the services being registered?
|
|
| | | |
Re: OSGI bundle dependencies [message #671421 is a reply to message #671393] |
Tue, 17 May 2011 19:53 |
rshelley Messages: 59 Registered: April 2010 |
Member |
|
|
Sure, I can absolutely provide some code
BundleA - WebShell - Web Bundle (WAR)
MANIFEST.MF
Virgo Screenshot of Bundle: http://screencast.com/t/kfq6r79u0z
Manifest-Version: 1.0
Unversioned-Imports: *
Bundle-ClassPath: .,WEB-INF/classes,WEB-INF/lib
Import-Library: org.springframework.spring;version="[3.0.0.RELEASE,3.0
.0.RELEASE]"
Web-ContextPath: /webshell
Import-Bundle: com.springsource.javax.ws.rs;version="[1.0.0,1.0.0]",co
m.springsource.javax.servlet;version="2.5.0",org.eclipse.virgo.web.dm
;version="2.1.1.RELEASE"
Bundle-Version: 0.1
Bundle-Activator: com.disney.ace.webshell.internal.WebShellActivator
Bundle-ManifestVersion: 2
Bundle-SymbolicName: com.disney.ace.webshell
Import-Package: com.disney.ace.webshell.directory,
javax.servlet;version="[2.5.0,2.5.0]",j
avax.servlet.http;version="[2.5.0,2.5.0]",javax.ws.rs,javax.ws.rs.cor
e,org.apache.log4j,org.osgi.util.tracker,org.osgi.framework
Export-Package: com.disney.ace.webshell.directory
BundleA - WebShell - DiscoveryService Interface (JAR in WAR)
Java Interface
package com.disney.ace.webshell.directory;
public interface IDirectoryService {
public String getService(String service, String method, String version);
}
BundleB - MockDirectoryService - JAR
MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Vendor: Disney Interactive Media Group
Bundle-SymbolicName: com.disney.ace.webshell.directory.mock
Bundle-Name: Mock Directory Service
Bundle-Version: 0.1.0
Import-Package:
org.apache.commons.logging;version="[1.1.1,1.1.1]",
com.disney.ace.webshell.directory;version="[0.0.0,0.1.0]"
Import-Library: org.springframework.spring;version=
"[3.0.0.RELEASE,3.0.0.RELEASE]"
Require-Bundle: com.disney.ace.webshell
BundleB - MockDirectoryService - Java
Java Implementation of DirectoryService
package com.disney.ace.webshell.directory.impl;
import com.disney.ace.webshell.directory.IDirectoryService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;
@Service
public class MockDirectoryServiceImpl implements IDirectoryService {
private static Log logger = LogFactory.getLog(MockDirectoryServiceImpl.class);
public String getService(String service, String method, String version){
return service + " - " + method + " - " + version;
}
}
[b]BundleB - MockDirectoryService - Spring/b]
Spring OSGI context
...
<context:component-scan base-package="com.disney.ace.webshell.directory" />
<!-- Exports the service implementation to other bundles by its service interface -->
<osgi:service ref="mockDirectoryServiceImpl" interface="com.disney.ace.webshell.directory.IDirectoryService" />
...
BundleB - Exception loading bundle in Virgo
region-dm-18 o.s.osgi.extender.internal.activator.ContextLoaderListener Application context refresh failed (OsgiBundleXmlApplicationContext(bundle=MockDirectoryService-0.1.0-SNAPSHOT, config=osgibundle:/META-INF/spring/*.xml)) org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.osgi.service.exporter.support.OsgiServiceFactoryBean#0': Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class[]' for property 'interfaces'; nested exception is java.lang.IllegalArgumentException: Cannot find class com.disney.ace.webshell.directory.IDirectoryService
Caused by: java.lang.ClassNotFoundException: com.disney.ace.webshell.directory.IDirectoryService
And for the record, I've tried dropping GreenPages into Virgo and it's always failed loading...
Thanks for your help. I really appreciate it!
|
|
| |
Goto Forum:
Current Time: Thu Dec 26 11:33:22 GMT 2024
Powered by FUDForum. Page generated in 0.04114 seconds
|