5

I would like to create some bundles which dependent on some other (3rd party) jars (whether this is a good practice is another topic)

I am able to use gradle to generate a fat jar (which has all dependent jars) and the osgi manifest

My project Layout store jars in the libs/ folder After making the jar, 3rd party jars (e.g. ibm.jar) are in the root of the jar.

I will My gradle task is using the osgi plugin with some basic osgi instruction, I specified only the export package as my program's package manually, but not other 3 jars

However, when I try to install that bundle it shows error

Error starting file:****.jar (org.osgi.framework.BundleException: Unresol
ved constraint in bundle ***** [24]: Unable to resolve 24.0: missi
ng requirement [24.0] osgi.wiring.package; (osgi.wiring.package=com.ibm.mq))
org.osgi.framework.BundleException: Unresolved constraint in bundle **** [24]: Unable to resolve 24.0: missing requirement [24.0] osgi.wiring.package; (osgi.wiring.package=com.ibm.mq)
        at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:382
6)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1868)
        at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1191)

        at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStart
LevelImpl.java:295)
        at java.lang.Thread.run(Unknown Source)

Gradle

task makeJar(type: Jar) {

from { 'libs/'}
manifest = osgiManifest {
        classesDir = sourceSets.main.output.classesDir
        classpath = sourceSets.main.runtimeClasspath
        instruction 'Export-Package','abc.def'  
        instruction 'Bundle-Vendor', 'ABC'
        instruction 'Bundle-Activator', 'abc.def.Activator'
        instruction 'Bundle-ClassPath', '.,*.jar'
        instruction 'Include-Resource', '@**/*.jar'
    }
}

I tried with below but it wont work, seems an issue of gradle http://issues.gradle.org/browse/GRADLE-1107

'Include-Resource', 'libs/'

I tried to explicity set them in classpath, but problem persist

Bundle-ClassPath: '.,*.jar' 

I can see the package I need (com.ibm.mq) is in Import-Package: is that correct?

My question is : what should be the correct manifest? Can the gradle (based on BND) understand the dependencies and automatically create the manifest, if so what is the required setup?

EDIT: With my gradle insturction like this, i am getting same error (I checked the bundle Class path appear in the manifest as well)

instruction 'Bundle-ClassPath', """.,felix.jar,org.springframework.aop-3.0.5.RELEASE.jar,org.springframework.asm-3.0.5.RELEASE.jar,c3p0-0.9.1.2.jar,com.springsource.net.sf.cglib-2.2.0.jar,org.springframework.context-3.0.5.RELEASE.jar,org.springframework.transaction-3.0.5.RELEASE.jar,com.ibm.mqjms.jar,org.springframework.beans-3.0.5.RELEASE.jar,org.springframework.core-3.0.5.RELEASE.jar,commons-io-1.4.jar,org.springframework.expression-3.0.5.RELEASE.jar,ojdbc14.jar,org.springframework.jdbc-3.0.5.RELEASE.jar,connector.jar,commons-lang-2.4.jar,commons-logging.jar,com.ibm.mq.jar,log4j-1.2.15.jar,org.springframework.web-3.0.5.RELEASE.jar"""
vincentlcy
  • 1,157
  • 2
  • 17
  • 19

1 Answers1

3

Bnd does not use wild cards for directories or files (for good reasons). If you need wildcard expansion on files, use the ${lsa;(dir);(match)} macro. See www.aqute.biz/Bnd for details.

Peter Kriens
  • 15,196
  • 1
  • 37
  • 55
  • Thanks a lot for answering. I tried with the option but seems the result manifest generated by gradle didnt handle the macro and put it ${lsa;libs;*.jar} right there. I tried to "hard code" the bundle classpath, and the resulted manifest include every jar in a manner like '.,com.ibm.jar,b.jar,c.jar' etc. However I am still getting same error. Is that related to 'include package', which still include com.ibm.mq. Should it be the case? I am not sure how gradle-bnd determine this 'include package'. Thanks! – vincentlcy Oct 30 '12 at 03:57
  • I have no idea what Gradle is doing but things like @**/*.jar do not work in bnd. 1) How does the manifest look now 2) Are the jars in the bundle? – Peter Kriens Oct 31 '12 at 07:46