You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by Tim Moloney <t....@verizon.net> on 2007/06/20 06:06:46 UTC
Example of building a bundle with embedded jars and native code?
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
Re: Example of building a bundle with embedded jars and native code?
Posted by Tim Moloney <t....@verizon.net>.
Stuart McCulloch wrote:
> [...]
>
> hope this helps.
Yes, this was a huge help. I can now compile and package my bundle.
I am working on missing runtime dependencies when I start my bundle.
Thanks,
Tim
Re: Example of building a bundle with embedded jars and native code?
Posted by Stuart McCulloch <st...@jayway.net>.
On 21/06/07, Tim Moloney <t....@verizon.net> wrote:
> 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.
>
> I may actually have this part working but I have compile errors (see
> below) so I'm not getting this far yet.
>
> I want to embed a set of third party libraries in my bundle. This
> consists of five jars and one native code library (dbus-java-bin.jar,
> debug-disable.jar, hexdump.jar, libdbus-java.jar, unix.jar, and
> libunix-java.so). All of these files are in the lib directory of my
> project. I've added the following line to the project's pom.xml.
>
> <Include-Resource>lib=lib</Include-Resource>
>
> That should embed the jar and so files. However, don't I still need a
> Bundle-NativeCode header? Something like
>
>
> <Bundle-NativeCode>lib/libunix-java.so;osname=Linux;processor=x86</Bundle-NativeCode>
>
> How might I do this?
just add that to the bundle-plugin instructions - it should be copied into
the manifest (same with any other entry beginning with a capital letter)
>
> > 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.
>
> 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.
>
> I guess that's my first problem. I believe that the Include-Resource
> line above does this but I am getting compile errors. The compiler
> can't find any of the classes in my embeded jars. How do I get the
compilation kicks in before the bundle-plugin - have you added maven
dependencies for these jars? (either compile scope, or system scope
if the jars only exist in the lib folder rather than from a maven repo)
> embedded jars added to the class path? My understanding is that the
> Bundle-ClassPath header is automatically generated from the dependencies
> in the project's pom file. However, the embedded jar files are in the
yes but the Bundle-ClassPath is different to the compilation classpath,
it is more of a runtime definition - the bundle-plugin only starts its work
once maven has compiled the classes.
> project directory, not in the maven repository. I'm pretty sure that my
> class path isn't correct which is why the compiler can't find the
> packages in the embeded jars.
>
I think you need to add something like the following for each lib jar:
<dependency>
<groupId>example</groupId>
<artifactId>example</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/example.jar</systemPath>
</dependency>
also, be aware that while embedded jars are visible to OSGi, they won't
be seen by the normal java compiler if you try to compile other sources
against your bundle (as javac doesn't handle embedded jars).
hope this helps.
> > -> 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
> >>
> >
>
>
--
Cheers, Stuart
Re[2]: Example of building a bundle with embedded jars and native code?
Posted by Peter Kriens <Pe...@aQute.biz>.
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
Re: Example of building a bundle with embedded jars and native code?
Posted by Tim Moloney <t....@verizon.net>.
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.
I may actually have this part working but I have compile errors (see
below) so I'm not getting this far yet.
I want to embed a set of third party libraries in my bundle. This
consists of five jars and one native code library (dbus-java-bin.jar,
debug-disable.jar, hexdump.jar, libdbus-java.jar, unix.jar, and
libunix-java.so). All of these files are in the lib directory of my
project. I've added the following line to the project's pom.xml.
<Include-Resource>lib=lib</Include-Resource>
That should embed the jar and so files. However, don't I still need a
Bundle-NativeCode header? Something like
<Bundle-NativeCode>lib/libunix-java.so;osname=Linux;processor=x86</Bundle-NativeCode>
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.
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.
I guess that's my first problem. I believe that the Include-Resource
line above does this but I am getting compile errors. The compiler
can't find any of the classes in my embeded jars. How do I get the
embedded jars added to the class path? My understanding is that the
Bundle-ClassPath header is automatically generated from the dependencies
in the project's pom file. However, the embedded jar files are in the
project directory, not in the maven repository. I'm pretty sure that my
class path isn't correct which is why the compiler can't find the
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
>>
>
Re: Example of building a bundle with embedded jars and native code?
Posted by Stuart McCulloch <st...@jayway.net>.
FYI, to play well with Eclipse PDE (which doesn't necessarily know about
embedded jars) I usually do the following:
1) use maven-dependency-plugin to copy compile time dependencies to
"target" folder
2) update Include-Resource to embed them inside the bundle as
"target/example.jar"
3) update the Bundle-ClassPath to include an entry for
"target/example.jar"
the benefit is that the jarfile in the project folder is where Eclipse PDE
expects it (based on the Bundle-ClassPath)
The latest version of Pax-Construct (which I'll mention in my OSGi Community
Event talk) provides a single script to do this for you (pax-embed-jar), as
long as you created the project using Pax-Construct - but this approach can
be used in any maven project.
You can also adapt this to unpack jars inside bundles while still keeping
Eclipse PDE happy:
1) use maven-dependency-plugin to copy compile time dependencies to
"target" folder
2) update Include-Resource to inline them inside the bundle using
"@target/example.jar"
( or use pull-approach of Bnd to include specific packages with
Private/Export-Package )
3) update the Bundle-ClassPath to include an entry for
"target/example.jar" -- this is just for PDE
4) add a zero-size placeholder jar to the bundle by updating
Include-Resource like so:
target/example.jar=placeholder.jar
where placeholder.jar is a zero-size file in your project -- this
is needed because of 3)
again, Pax-Construct can do this for you (add "-- -Dunpack=true" to the
pax-embed-jar command).
On 20/06/07, Richard S. Hall <he...@ungoverned.org> 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.
>
> 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.
>
> 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.
>
> -> 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
> >
>
--
Cheers, Stuart
Re: Example of building a bundle with embedded jars and native code?
Posted by "Richard S. Hall" <he...@ungoverned.org>.
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.
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.
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.
-> 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
>