felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Kriens <Peter.Kri...@aQute.biz>
Subject Re[2]: Example of building a bundle with embedded jars and native code?
Date Thu, 21 Jun 2007 08:27:06 GMT
You use parts of different strategies, and get bitten. :-)

If you want to compile, the bundles need to be specified as maven
dependencies or the compiler will not see them.

By copying the lib directory in the bundle, you get them in the bundle
but they are not visible to the compiler, nor to the bundle because
they are not on the bundle classpath during runtime.

So you must add the jars in the lib directory to maven as dependencies
to get them to compile.

If that compiles, you have the problem to make the classes visible
during runtime in the OSGi environment. There are different strategies
to do this. You can expand the jars or you can copy them and put them
on the Bundle-Classpath.

The fastest solution during runtime is to expand these jars by using the @
operator.

 <Include-Resource>
   @dbus-java-bin.jar,
   @debug-disable.jar,
   @hexdump.jar,
   @libdbus-java.jar,
   @unix.jar,
   lib/libunix-java.so
 </Include-Resource>
 <Bundle-NativeCode>
   libunix-java.so;osname=Linux;processor=x86
 </Bundle-NativeCode>

The @ sign will expand the jar in the output bundle. This is the most
efficient way you can do it. However, you must name all the files
(again), which is not nice. I guess I should take another look at the
@operator and see if I can make it work with wildcards.

Alternatively, you could use the Bundle-Classpath. You copy the lib
directory in the bundle and set the Bundle-Classpath to all the jar
files in that directory. The ${findpath;regexp[;replacement]} macro is
recent in bnd; it will traverse the files in the built jar file and
check each path with the regular expression. If the regexp matches it
puts it on a comma separated list. This allows us to construct the
Bundle-Classpath from the lib directory in the built jar.

 <Include-Resource>lib=lib</Include-Resource>
 <Bundle-Classpath>${findpath;lib/.*.jar}</Bundle-Classpath>
 <Bundle-NativeCode>
   libunix-java.so;osname=Linux;processor=x86
 </Bundle-NativeCode>

The proposal in JIRA is a bit nicer because it synchronizes the maven
classpath with the classpath of jar being build. There is some
redundancy in the previous examples that can bite you when you modify
the classpath.

Hope this helps, kind regards,

     Peter Kriens
     


TM> Richard S. Hall wrote:
>> Well, from my understanding of the situation, I think that embedding 
>> the native library should be reasonably straightforward using the 
>> Bundle Plugin...you just need to copy the native library into your 
>> bundle using <Include-Resource>, assuming that the native library is a 
>> resource in your project.

TM> I may actually have this part working but I have compile errors (see 
TM> below) so I'm not getting this far yet.

TM> I want to embed a set of third party libraries in my bundle.  This 
TM> consists of five jars and one native code library (dbus-java-bin.jar, 
TM> debug-disable.jar, hexdump.jar, libdbus-java.jar, unix.jar, and 
TM> libunix-java.so).  All of these files are in the lib directory of my 
TM> project.  I've added the following line to the project's pom.xml.

TM>   <Include-Resource>lib=lib</Include-Resource>

TM> That should embed the jar and so files.  However, don't I still need a
TM> Bundle-NativeCode header?  Something like

TM>   
TM> <Bundle-NativeCode>lib/libunix-java.so;osname=Linux;processor=x86</Bundle-NativeCode>

TM> How might I do this?

>> The trickier part is dealing with the embedded JAR file, since Bundle 
>> Plugin doesn't handle embedding JARs very well at present. There was a 
>> proposal on how to deal with this in this mailing list thread:
>>
>> http://mail-archives.apache.org/mod_mbox/felix-dev/200701.mbox/%3c45B9147F.6010504@ungoverned.org%3e

>>
>>
>> I guess we just need to actually implement the proposal now and that 
>> would solve your embedded JAR issue...I will create a JIRA issue out 
>> of this message and we can try to convince someone to work on it.

TM> I saw FELIX-308, thanks.

>> In the meantime, you could use the old plugin to embed your 
>> dependencies...
>>
>> Of course, all of this assumes that your embedded JAR files are maven 
>> dependencies in the first place...if they are just resources in your 
>> project, then you could use <Include-Resource> for them too.

TM> I guess that's my first problem.  I believe that the Include-Resource 
TM> line above does this but I am getting compile errors.  The compiler 
TM> can't find any of the classes in my embeded jars.  How do I get the 
TM> embedded jars added to the class path?  My understanding is that the 
TM> Bundle-ClassPath header is automatically generated from the dependencies
TM> in the project's pom file.  However, the embedded jar files are in the
TM> project directory, not in the maven repository.  I'm pretty sure that my
TM> class path isn't correct which is why the compiler can't find the 
TM> packages in the embeded jars.

>> -> richard
>>
>> Tim Moloney wrote:
>>> I'm trying to build a bundle that has both embedded jar files and a 
>>> native code library.  I've been looking for documentation/examples of 
>>> how to build such a beast using maven and I've been unsuccessful.  As 
>>> an added bonus, I'd like to figure out how to use 'mvn 
>>> eclipse:eclipse' to create the Eclipse files necessary to build this 
>>> beast inside Eclipse.  I've created a project from scratch in Eclipse 
>>> and can successfully build it there but I'd like to 'mavenize' the 
>>> process.
>>>
>>> I did find the "simple" bundle in the Felix repo and I even found 
>>> Felix-61 which should answer all my questions when it is completed.
>>>
>>> Can anyone point out any documentation/examples that might help?  
>>> Would someone wise in the ways of Maven/OSGi be willing to work on 
>>> Felix-61?
>>>
>>> Thanks,
>>>  Tim
>>>
>>


-- 
Peter Kriens                              Tel +33467542167
9C, Avenue St. Drézéry                    AOL,Yahoo: pkriens
34160 Beaulieu, France                    ICQ 255570717
Skype pkriens                             Fax +1 8153772599


Mime
View raw message