2

I am developing OSGi application using 'bnd-maven-plugin' https://github.com/bndtools/bnd/tree/master/maven/bnd-maven-plugin

I have many third party jars in my project, referenced through maven.

When I create jar bundle using 'maven install', I will get it and when I deploy it on felix, it will not get resolved other dependent third party jars.

It is working with 'maven-bundle-plugin' http://www.lucamasini.net/Home/osgi-with-felix/creating-osgi-bundles-of-your-maven-dependencies

POM file with 'bnd-maven-plugin' given below:

<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>XYZ.Models</groupId>
    <artifactId>XYZ.Models</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <dependencies>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>


        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>

    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>biz.aQute.bnd</groupId>
                <artifactId>bnd-maven-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>bnd-process</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <archive>

                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Below one is working POM for 'maven-bundle-plugin'

<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>XYZ.Models</groupId>
    <artifactId>XYZ.Models</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <dependencies>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
            <scope>provided</scope>
        </dependency>


        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>create-osgi-bundles-from-dependencies</id>
            <build>
                <directory>${basedir}/bundles</directory>
                <plugins>

                    <plugin>
                        <groupId>org.apache.felix</groupId>
                        <artifactId>maven-bundle-plugin</artifactId>
                        <version>2.0.1</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>wrap-my-dependency</id>
                                <goals>
                                    <goal>wrap</goal>
                                </goals>
                                <configuration>
                                    <wrapImportPackage>;</wrapImportPackage>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>
Umesh Rajani
  • 139
  • 2
  • 13
  • There doesn't seem to be a question here. – Neil Bartlett Oct 20 '16 at 16:38
  • Hello @NeilBartlett Thank you. Where can I post query related to 'bnd-maven-plugin', I don't find much other than your nicely explained article for this plugin. – Umesh Rajani Oct 21 '16 at 05:53
  • 1
    So why don't you just use *maven-bundle-plugin* if it works with that? – stempler Oct 21 '16 at 07:22
  • 1
    @UmeshRajani You can post questions here but I can't see an actual question above. – Neil Bartlett Oct 21 '16 at 09:20
  • Hi Neil, Actually we have one project module which has 20-30 external jar dependency, when I just do 'maven install' I will get one myproject_osgi.jar and when I deploy on felix, it should resolve all the third party jar dependency, but it is not. So what is the way to do it? should I deploy all third party jar first on felix? (our higher tech team concluded to use 'bnd-maven-plugin' only) – Umesh Rajani Oct 21 '16 at 09:38
  • I didn't understand this: "it should resolve all the third part jar dependency". Who is "it" here? Why would this happen? Have you provided all of the dependencies? – Neil Bartlett Oct 21 '16 at 22:50
  • Hi Neil, I have given POM file with 'bnd-maven-plugin' above, when I do 'mvn install' I will get 'xyz.jar' and then I can install it on felix and if I start I will get the error like "org.osgi.framework.BundleException: Unresolved constraint in bundle xyz [9]: Unable to resolve 9.0: missing requirement [9.0] osgi.wiring.package; (&(osgi.wiring.package=com.google.gson)(version>=2.2.0)(!(version>=3.0.0)))" – Umesh Rajani Oct 24 '16 at 09:17

2 Answers2

1

The magic in maven-bundle-plugin is done by <wrapImportPackage>;</wrapImportPackage> which basically would add all your dependencies as resources in the generated jar file and configure the bundle classpath for you.

bnd-maven-plugin does not use instructions in the POM. You have to do that in bnd file. This tutorial is specific for Liferay and Gradle, but it will show you an example of -includeresource instruction and how to set your bundle classpath.

Milen Dyankov
  • 2,972
  • 14
  • 25
0

As above rightly mention about bnd-maven-plugin. you can also take a reference from bndtools and - wcm.io already but just adding few line for example if it help.

 <configuration>
     <bnd><![CDATA[
         Include-Resource: <EXAMPLE-GROUP-ID>*.jar;<ANOTHER>.*;
     ]]></bnd>
</configuration>

you can use wildcard according to your requirement. i have just added example.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Vikka
  • 159
  • 3