java - org.osgi.framework.BundleException: Unresolved constraint in bundle SampleModel -
i trying launch osgi framework programatically. using felix framework this. below code have launch osgi container.
public goldeneyeapp() { try { frameworkfactory frameworkfactory = serviceloader.load(frameworkfactory.class).iterator().next(); map<string, string> config = new hashmap<string, string>(); //todo: add config properties framework framework = frameworkfactory.newframework(config); framework.start(); bundlecontext bundlecontext = framework.getbundlecontext(); modulesnameversionholder.put("samplemodel", "1.0.0"); list<bundle> installedbundles = new linkedlist<bundle>(); string basepath = "c:\\clienttool\\localstorage"; (map.entry<string, string> entry : modulesnameversionholder.entryset()) { string version = entry.getvalue(); final string filename = name + constants.dash + version + constants.dotjar; final string localfilename = constants.file_protocol + basepath+ file.separatorchar + filename; installedbundles.add(bundlecontext.installbundle(localfilename)); } (bundle bundle : installedbundles) { bundle.start(); // line throws exception start samplemodel bundle } } catch (bundleexception e) { e.printstacktrace(); } }
in above code, trying install , start simple osgi module (samplemodel jar) have created. try start module, below exception-
org.osgi.framework.bundleexception: unresolved constraint in bundle samplemodel [6]: unable resolve 6.0: missing requirement [6.0] osgi.wiring.package; (&(osgi.wiring.package=net.sf.cglib.core)(version>=2.1.3)(!(version>=3.0.0))) @ org.apache.felix.framework.felix.resolvebundlerevision(felix.java:3974) @ org.apache.felix.framework.felix.startbundle(felix.java:2037) @ org.apache.felix.framework.bundleimpl.start(bundleimpl.java:955) @ org.apache.felix.framework.bundleimpl.start(bundleimpl.java:942) @ com.host.stream.goldeneye.goldeneyeapp.<init>(goldeneyeapp.java:62) @ java.lang.j9vminternals.newinstanceimpl(native method) @ java.lang.class.newinstance(class.java:1345) @ com.host.jetstream.application.jetstreamapplication.getinstance(jetstreamapplication.java:71) @ com.host.jetstream.application.jetstreamapplication.main(jetstreamapplication.java:94)
below samplemodel pom.xml file-
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupid>com.host.domain</groupid> <artifactid>domainparent</artifactid> <version>1.6.1-release</version> </parent> <!-- pom information project --> <modelversion>4.0.0</modelversion> <groupid>com.host.sample.model</groupid> <artifactid>samplemodel</artifactid> <version>1.0.0</version> <!-- packing type bundle osgi library bundle --> <packaging>bundle</packaging> <dependencies> <dependency> <groupid>org.springframework</groupid> <artifactid>org.springframework.beans</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>org.springframework.context</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>org.springframework.core</artifactid> </dependency> <dependency> <groupid>org.apache.servicemix.bundles</groupid> <artifactid>org.apache.servicemix.bundles.cglib</artifactid> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <scope>test</scope> </dependency> <dependency> <groupid>org.osgi</groupid> <artifactid>org.osgi.core</artifactid> <version>4.3.0</version><!--$no-mvn-man-ver$ --> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupid>org.osgi</groupid> <artifactid>org.osgi.compendium</artifactid> <version>4.3.0</version><!--$no-mvn-man-ver$ --> <type>jar</type> <scope>compile</scope> </dependency> </dependencies> <!-- build configration --> <build> <plugins> <!-- apache felix bundle plugin - generation of manifest after compile phase --> <plugin> <groupid>org.apache.felix</groupid> <artifactid>maven-bundle-plugin</artifactid> <configuration> <manifestlocation>src/main/resources/meta-inf</manifestlocation> <instructions> <bundle-symbolicname>samplemodel</bundle-symbolicname> <bundle-activator>com.host.sample.model.samplemodel.activator.activator</bundle-activator> <import-package>*, org.springframework.beans.factory;version="[3.0.5.release,4.0.0)", org.springframework.beans.factory.config;version="[3.0.5.release,4.0.0)", net.sf.cglib.core;version="[2.1.3,3.0.0)", net.sf.cglib.proxy;version="[2.1.3,3.0.0)", net.sf.cglib.reflect;version="[2.1.3,3.0.0)" </import-package> </instructions> </configuration> </plugin> </plugins> </build> <!-- configuration of repositories dependency resolution --> <repositories> <!-- domain bundles repository --> <!-- needed locate domain parent project. other repositories come parent. --> <repository> <id>releases</id> <url>http://nxdomain/content/repositories/releases/</url> <releases> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>thirdparty</id> <url>http://nxdomain/content/repositories/thirdparty/</url> <releases> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </project>
you using 'import-package: net.sf...' in manifest haven't installed cglib(or spring framework) osgi runtime yet. if import-package doesn't resolve every required package, bundle won't start.
edit: forgot had this: https://gist.github.com/sheenobu/5935468 . if pax-url working, can start installing arbitrary urls.
edit2: clear frameworks cache otherwise end installing packages multiple times. or check if package installed bundle and, if so, don't install it.
Comments
Post a Comment