OSGi: Recalculate the Import-Package of a JAR programmatically

72 views Asked by At

I want to recalculate the "Import-Package" of an OSGi Jar programmatically. I try to use the bnd Analyser.

    try(Analyzer analyzer = new Analyzer()) {
        analyzer.setJar(new File(filename));
        return analyzer.getImportPackage();
    }

This returns the (wrong) existent imports of the MANIFEST.MF. How can I recalculate the "Import-Package" of an OSGi Jar programmatically?

Update Adding as BJ Hargrave calMainfest() suggested does not work:

try(Analyzer analyzer = new Analyzer()) {
    analyzer.setJar(new File(filename));
    analyzer.calcManifest(); 
    return analyzer.getImportPackage();
}

It seems to use the existing MANIFEST.MF contained in the Jar. Best regards Kisho

1

There are 1 answers

2
BJ Hargrave On

You need to call calcManifest() to compute a new manifest. Otherwise it just uses the existing manifest.