Home » Eclipse Projects » Virgo » OSGI bundle dependencies
OSGI bundle dependencies [message #671393] |
Tue, 17 May 2011 13:55  |
Eclipse User |
|
|
|
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 15:53   |
Eclipse User |
|
|
|
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!
|
|
|
Re: OSGI bundle dependencies [message #671454 is a reply to message #671421] |
Tue, 17 May 2011 20:07  |
Eclipse User |
|
|
|
I think I may have discovered major parts of the problem.
1) Maven's build process was overwriting my MANIFEST.MF and putting it's own (virtually empty) one in place. I had to futz with the POM to get it to work right. This was confusing because the right manifest was in place in the target/classes/META-INF folder, but was incorrect when checking the JAR itself. Here's my new <build> definition:
<build>
<resources>
<!-- standard Maven folder -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>META-INF/MANIFEST.MF</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>com.springsource.bundlor</groupId>
<artifactId>com.springsource.bundlor.maven</artifactId>
<version>1.0.0.M2</version>
<configuration>
<outputManifest>${basedir}/src/main/resources/META-INF/MANIFEST.MF</outputManifest>
<failOnWarnings>false</failOnWarnings>
<removeNullHeaders>true</removeNullHeaders>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>package</phase>
<goals>
<goal>manifest</goal>
<goal>transform</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</configuration>
</plugin>
</plugins>
</build>
2) It doesn't seem to like unversioned exports. I used the source code from the book you recommended to compare mine and after much back-and-forth, I finally have a manifest that's exporting and importing. I was also using Bundlor's Import-Template and a bunch of optional stuff that I could simplify out just to get things to work. Here's my new simplified manifest:
Manifest-Version: 1.0
Unversioned-Imports: *
Bundle-Classpath: .
Built-By: rshelley
Bundle-Name: client
Bundle-Version: 0.1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: com.disney.ace.webshell.directory
Import-Package: com.disney.ace.webshell.directory;version="[0.1.0,0.1.
0]"
At this point, I have another bundle that is successfully importing the interface. That bundle is also registering a service (as per Virgo's bundle info). I have not yet got to the "using of the service" part, but I'm a couple of steps closer.
|
|
|
Goto Forum:
Current Time: Tue Jul 01 11:09:38 EDT 2025
Powered by FUDForum. Page generated in 1.64478 seconds
|