Pregunta

We have the following scenario using OSGi bundles:

BundleA imports package "com.mypackage".

BundleB exports package "com.mypackage", but that package is from a nested JAR file added to the BundleB classpath.

In order to compile the OSGi bundles and resolve their dependencies automatically I'm using ANT + IVY.

I configured an ivy:buildobr task and it correctly builds the OBR file (checked manually).

Next I configured the actual build task.

  1. call ivy:resolve. I can clearly see that IVY correctly resolves package "com.mypackage".
  2. call ivy:cachepath that creates the compile class path.
  3. call javac with classpathref="compile.classpath"

javac throws error because it doesn't know about package "com.mypackage". It only knows about the classpath indicating the JAR files, and doesn't know how to interpret the MANIFEST.MF with it's own classpath.

The problem is with the constructed class path. It has no idea about the exported "com.mypackage" from the nested JAR in BundleB.

How do you solve this kind of issue?

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: BundleA
Bundle-SymbolicName: BundleA
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: com.mypackage,
 org.osgi.framework;version="1.3.0"
Bundle-ClassPath: .


Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: BundleB
Bundle-SymbolicName: BundleB
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework;version="1.3.0"
Export-Package: com.mypackage
Bundle-ClassPath: .,
nestedJarContainingComMypackage.jar

Thanks

¿Fue útil?

Solución

You can't do this. The javac compiler simply does not understand JARs nested inside JARs. That is a runtime feature of the OSGi Framework.

To build against these APIs you will have to pull out the inner JAR and put it onto your build-time classpath. You can still use the nested JAR the way you wanted to at runtime, however.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top