Avoid copying some packages to OSGi Bundle

683 views Asked by At

I want to exclude some packages from copying when creating an OSGi bundle using maven bundle plugin.

I used !package name in the export section. But since I'm using @openejb-core-${openejb.version}.jar!/**, in the include-resource section that package gets copied to the bundle.

How can I avoid copying a particular package or set of packages using maven bundle plugin?

I can use names in resource section, but I'd rather not list them one by one.

1

There are 1 answers

1
d33t On

Typically your build section of an osgi bundle looks like this:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-scr-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-Category>Your Category/Company</Bundle-Category>
                    <Import-Package>
                       <!-- put here some optional depependencies which are already provided by other bundles -->
                        org.apache.lucene.*;resolution:=optional,
                        *
                    </Import-Package>
                    <Export-Package>
                        com.yourproject.code.to.be.exported.*;version=${project.version}
                        <!-- exclude packages by negating with the prefix !, see http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html for more info -->
                        !com.do.not.include.package.*;version=x.y.z
                    </Export-Package>
                    <Embed-Dependency><!--put here some thirdparty artifacts you want to embed in your bundle--></Embed-Dependency>
                    <Include-Resource>{maven-resources}</Include-Resource>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

See also http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html