Including native resources in the bundle

957 views
Skip to first unread message

Raymond Augé

unread,
May 30, 2011, 2:06:13 PM5/30/11
to bndtool...@googlegroups.com
Hello All,

I'm trying to merge set of non-osgi jars into a bundle that includes the native resources for a variety of platforms (not part of the jars). 

Step one of setting up the bundle using bndtools works fine. I have then added the bundle header "Bundle-NativeCode" with what I believe is the correct pattern:

Bundle-NativeCode: native/linux/lib1.so;\
native/linux/lib2.so;\
native/linux/lib3.so;\
osname=Linux;processor=x86,\
...

Beyond this I can't seem to produce a bundle jar which includes the referenced native resources.

Bnd complains:
Multiple markers at this line
- Native library not found in JAR: native/linux/lib1.so
...

I can't find among the bnd switches any which allow for inclusion of static/native resources (static because I'd also like to include some images which are also not in the original jars), nor does adding these resources to the "-classpath:" switch seem to work.

Is there a trick for adding these to the "-buildpath:" directive?

thx

Dave Reynolds

unread,
May 30, 2011, 2:30:27 PM5/30/11
to bndtool...@googlegroups.com
On Mon, 2011-05-30 at 11:06 -0700, Raymond Augé wrote:

>
> I can't find among the bnd switches any which allow for inclusion of
> static/native resources (static because I'd also like to include some
> images which are also not in the original jars), nor does adding these
> resources to the "-classpath:" switch seem to work.

Include-Resource lets you include resources, or directories of
resources, in your bundle - allowing you to map the source location to
the location within the bundle. Works nicely for things like images.

Dave

Peter Kriens

unread,
May 31, 2011, 1:41:36 AM5/31/11
to bndtool...@googlegroups.com
This allows you to do whatever layout you want in your JAR: http://www.aqute.biz/Bnd/Format#include-resource

Kind regards,

Peter Kriens

Raymond Auge

unread,
May 31, 2011, 2:16:44 PM5/31/11
to bndtool...@googlegroups.com
Thanks Peter,

It seems that the built in ant targets included with bndtools eclipse
plugin don't allow for this level of control. So, I'm going to have to
start a project from scratch.

Ray

--
Raymond Augé (twitter)
Senior Software Architect
Liferay, Inc. (#liferay)

---

Hungary Symposium
May 26, 2011
Register today! www.liferay.com/hungary2011
France Symposium 2011
June 15, 2011
Register today! www.liferay.com/France2011

Neil Bartlett

unread,
May 31, 2011, 2:49:40 PM5/31/11
to bndtool...@googlegroups.com
Hi Ray,

I'm not sure what you mean by this. Ant gives you exactly as much
control as bnd, because it uses bnd.

Regards,
Neil

Raymond Auge

unread,
May 31, 2011, 3:49:44 PM5/31/11
to bndtool...@googlegroups.com
What I meant was that the project generated by bndtools (and ant
targets linked back from the "cnf" project) don't support these
operations.

i.e. when I setup the project and supply jar files to the wizard, it
always fails to find the native resources define in the bnd.bnd file
(because the default targets try to run "bndprepare" on the jars
before my project has any chance to override the init settings).

It's a "chicken or the egg" problem. I need to manipulate the bnd.bnd
descriptor, but project is always calling the bndprepare ant task on
the jars in the bundle path, but doesn't resolve the native resources
no matter if they are in jars in the bundle path or not!

Maybe I'm going about this the wrong way... but there is no step by
step guide anywhere on how to do this.

This is what is leading me toward the conclusion that the
"wizard-ized" project doesn't handled the scenario I'm trying to
tackle.

FYI, for sake of openness what I'm trying to do is wrap lwjgl
(http://lwjgl.org) in a single OSGi bundle.

So, what was doing was to taking the resources and jars that are
provided (there are ~6-7 jars, and 2 folders worth of resources, some
being the native libraries for the various platforms) and essentially
merge those into a single bundle (exposing of course only the lwjgl
APIs).

- Ray

Peter Kriens

unread,
Jun 1, 2011, 2:58:56 AM6/1/11
to bndtool...@googlegroups.com
I do not think you need anything beyond what you've already got. Just create a bnd project and for each jar you want to make you create a bnd descriptor.

org.lwjgl
bnd.bnd -> multi descriptor
core.bnd
Include-Resource: \
@jar/lwjgl.jar, \
native/linux/liblwjgl.so, \
native/linux/liblwjgl64.so, \
native/macosx/liblwjgl.jnlib, \
native/solaris/liblwjgl.so, \
native/solaris/liblwjgl64.so, \
native/windows/lwjgl.dll, \
native/windows/lwjgl64.dll
Bundle-NativeCode: ....
util.bnd
Include-Resource: \
@jar/lwjgl_util.jar, \
...

Anyway, this should make it clear how you can set this up. One warning, OSGi cannot handle dependencies between native libraries, you'll have to make sure yourself that libraries are loaded in proper order. Included you find a mail that Holger Hofstatte from Paremus sent to the Apache Felix list that is a very fundamental and great treatise of the subject.

Kind regards,

Peter Kriens

Raymond Auge

unread,
Jun 1, 2011, 9:05:22 AM6/1/11
to bndtool...@googlegroups.com
Sincere thanks Peter.

I'll approach it this way.

I'll update the status of this as soon as I get some more free time to
work on it (it's a side project.)

- Ray

Reply all
Reply to author
Forward
0 new messages