4

As we know that by defaul osgi export-package only export the package from src/main/java folder, but i need the other file form src/main/resource also to be exported to use by other projects. Below is the example of my

ProjectA (packaging type is jar)

src/main/java
                x.y.z.SomeClass.java
src/main/resource 
                x.y.z.config.SomeConfigFile.xml


pom.xml contains 
    <Export-Package>
        x.y.z.*,
        x.y.z.config.*,
        *
    </Export-Package>

ProjectB (packaging type is bundle)

src/main/java
                a.b.c.AnotherClass.java
src/main/resource 
                a.b.c.config.AnotherConfigFile.xml


pom.xml contains 
    <Import-Package>
        x.y.z.*,
        x.y.z.config.*,
        *
    </Import-Package>

Here my requirement is to use SomeConfigFile.xml of ProjectA into AnotherConfigFile.xml of projectB but i always get FileNotFoundException for the above scenario. Please help me use the src/main/resource classpath files into another osgi project. How i can achieve the above defined scenario.

vashishth
  • 2,751
  • 4
  • 38
  • 68

2 Answers2

1

You should probably use Include-Resource instead of Import-Package. More info on the header here (in the 'headers' section): http://www.aqute.biz/Bnd/Format.

Paul Bakker
  • 1,024
  • 7
  • 9
  • I have tried using, {maven-resources},{maven-dependencies} in my bundle project pom, but no luck yet :( – vashishth Mar 28 '14 at 10:21
1

There can be several issues (I guess it is option one but the others might be useful as well)

  1. If there is no java class usage, you must specify the required package exactly at the Import-Package section. You cannot use asterisk.
  2. If you want to export a package that is under META-INF, in the Export-Package section you must define it with a quote and an equality character. E.g: '=META-INF.subdir'
  3. If you want to access a resource that is in an imported package, you cannot use the bundle.getResource() function as it searches only in the current bundle. You must use the classLoader of the bundle or the or listResources function of BundleWiring.
Balazs Zsoldos
  • 6,036
  • 2
  • 23
  • 31
  • Hi @Balazs, can you please share some online documents where i could gain more context around using your 3rd option i.e. using classloader of bundle. – Hemant Mar 28 '14 at 10:19
  • I think the most detailed doc is the javadoc of Bundle.getResource() and the javadoc of BundleWiring functions. The javadoc of BundleWiring class tells you how to obtain a BundleWiring instance from Bundle. – Balazs Zsoldos Mar 28 '14 at 12:09