'. '

OSGiWrapper

From APIDesign

Revision as of 13:05, 29 November 2014 by JaroslavTulach (Talk | contribs)
Jump to: navigation, search

Not all artifacts in a Maven repository are packaged as OSGi bundles. Yet, some systems (like for example the Bck2Brwsr ahead-of-time compiler) require JAR to contain OSGi meta-data. Luckily there is a simple way to turn any JAR into OSGi bundle by creating a simple Maven project. Here is the sample pom.xml:

?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>your.group.id</groupId>
    <artifactId>jar-id</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>bundle</packaging> <!-- we want to produce an OSGi bundle -->
 
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
 
    <dependencies>
        <!-- specify the dependency you want to wrap as OSGi bundle -->
        <dependency>
            <groupId>org.netbeans.external</groupId>
            <artifactId>nb-javac-api</artifactId>
            <version>RELEASE80</version>
            <!-- we need the dependency only during compilation -->
            <scope>provided</scope>
        </dependency>
    </dependencies>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <!-- export the packages that should be accessible -->
                        <Export-Package>javax.*</Export-Package>
                        <!-- list other packages that should be included in your bundle -->
                        <Private-Package>com.sun.tools.*</Private-Package>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

And that is all! After building the project, you'll get an OSGi bundle that contains all the classes from the specified dependency found in exported and private packages.

Wrap your JAR's into OSGi bundles and let Bck2Brwsr obfuscate them per library.

Personal tools
buy