2 Replies Latest reply on May 18, 2010 5:21 AM by walter.accantelli

    How to import third-part libraries?

    walter.accantelli

      Hi all,

        I'm developing an eip osgi that use a third-part library (No-sql mongodb  library).

       

      In my pom.xml I added the import row:

      <Import-Package>

           ...

           com.mongodb;version="1.4",

           ...

      </Import-Package>

       

      When I try to install my osgi bundle I get the following error:

      The bundle could not be resolved. Reason: Missing Constraint: Import-Package: com.mongodb; version="1.4.0"

       

      Now, how can I import a third-part library in my osgi?

      Can I include that library in my osgi (i.e., in a sub lib folder) or I have to install it as a separate osgi? In this case, I follow the instructions to convert a jar lib into a osgi bundle you provide  here, but it doesn't work.

       

      What is the best practice to import a third part library?

       

      Regards,

      walter

        • 1. Re: How to import third-part libraries?
          ffang

          Hi,

           

          This error shows you didn't install OSGi bundle jar correctly which contain com.mongodb package.

           

          IMHO install third party lib as separate OSGi bundle jar is a good practice in OSGi container, so that more bundles can use it.

           

          Also you can put the third party lib(I don't recommand you to do it) in your OSGi bundle under certain folder, but you need add Class-Path OSGi header, also in this case you shouldn't add Import-Package header, as Import-Package will always try to look for the package from other bundles which export it.

           

          You said you can't convert a jar to OSGi bundle, then what's the problem you encounter?

           

          Freeman

          • 2. Re: How to import third-part libraries?
            walter.accantelli

            Thank you very much, I solved.

             

            Just remove the line from pom.xml

             

            <Import-Package>

            ...

            com.mongodb;version="1.4",

            ...

            </Import-Package>

             

            and follow the instruction to convert a simple jar (in my case, mongo-db.jar) into a osgi bundle (mongo-db.bar) as described in fuse documentation, Chapter 5: Deploying a JAR Library (below the instructions I follow).

             

            -


             

            Download bnd.jar from http://www.aqute.biz/Code/Download#bnd

             

            (this generate mongo-db-1.4.bar)

            java -jar bnd.jar wrap mongo-db-1.4.jar

             

            (deploy mongo-db-1.4.bar bundle)

            cp mongo-db-1.4.bar $FUSE_HOME/deploy

             

            $ osgi:list

            mongo-db-1.4 (0)

            My Bundle That Use MongoDB (0.1)

             

            -


             

            Thank you very much.

             

            walter

             

            Edited by: walter.accantelli on May 18, 2010 9:20 AM

             

            Edited by: walter.accantelli on May 18, 2010 9:21 AM