bnd-maven-plugin -- approach to using bundle-classpath

1,147 views
Skip to first unread message

Benson Margulies

unread,
Jun 27, 2016, 10:05:11 AM6/27/16
to bndtools-users
I would like to migrate away from the maven-bundle-plugin to the bnd-maven-plugin. However, I have to deal with a number of Maven projects which have the job of combining several non-OSGi jars into one bundle. The goal of the exercise is to end up with a working OSGi bundle that has accurate dependencies seen downstream.

Using the bundle classpath has some advantages over using the maven-shade-plugin. It obviates all merging and other management of other java metadata. 

I could use the maven-dependency-plugin to fetch the jars to embed, and at that point I'm at the limit of my bnd knowledge. What do I put in the bnd file to suck in the jars and set up the header?

BJ Hargrave

unread,
Jun 27, 2016, 10:07:02 AM6/27/16
to bndtool...@googlegroups.com
You can use -includeresource to add resources like jar in the bundle. Then you can add a Bundle-Classpath header in the bnd file.

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
--
BJ

Raymond Auge

unread,
Jun 27, 2016, 10:35:55 AM6/27/16
to bndtool...@googlegroups.com
Since bnd 3.2, there's a very clever feature you can use with the -includeresource instruction which helps automate the task of working with Bundle-Classpath, and which can also find libraries in your buildpath in a portable way.

Like so:

-includeresource: lib/=commons-digest-.*\.jar;lib:=true

where `commons-digest-.*\.jar` is a litteral regex matching the `A-V.jar` for a given maven GAV.


the `lib:=true` directive tells the -includeresource to append this jar to the Bundle-Classpath, adding the header (including adding a default of `.`) if there isn't one but simply appending it if there's already a value defined.

- Ray
Raymond Augé (@rotty3000)
Senior Software Architect Liferay, Inc. (@Liferay)
Board Member & EEG Co-Chair, OSGi Alliance (@OSGiAlliance)

Benson Margulies

unread,
Jun 29, 2016, 7:51:19 AM6/29/16
to bndtool...@googlegroups.com
On Mon, Jun 27, 2016 at 10:35 AM, Raymond Auge <raymon...@liferay.com> wrote:
> .*\.jar;lib:=true


My first effort here is not wildly successful. Do I also need to use
the dependency plugin to fetch the dependencies to a directory?

I wrote:

-includeresource: \
jaxb-api-.*\.jar;lib:=true, \
javax.json-api-.*\.jar;lib:=true, \
ejml-.*\.jar;lib:=true, \
stanford-corenlp-.*\.jar;lib:=true, \
jollyday-.*\.jar;lib:=true

and got:

[ERROR] /Users/benson/x/dependency-parser-wrapper/api/bnd.bnd [0:0]:
Input file does not exist: jaxb-api-.*.jar
[ERROR] /Users/benson/x/dependency-parser-wrapper/api/bnd.bnd [0:0]:
Input file does not exist: javax.json-api-.*.jar
[ERROR] /Users/benson/x/dependency-parser-wrapper/api/bnd.bnd [0:0]:
Input file does not exist: ejml-.*.jar
[ERROR] /Users/benson/x/dependency-parser-wrapper/api/bnd.bnd [0:0]:
Input file does not exist: stanford-corenlp-.*.jar
[ERROR] /Users/benson/x/dependency-parser-wrapper/api/bnd.bnd [0:0]:
Input file does not exist: jollyday-.*.jar

Benson Margulies

unread,
Jun 29, 2016, 8:07:55 AM6/29/16
to bndtool...@googlegroups.com
The files do exist in the path specified to the right of the = sign.
Where is bnd looking?

Benson Margulies

unread,
Jun 29, 2016, 8:20:49 AM6/29/16
to bndtool...@googlegroups.com
I debugged through bnd 3.2.0, and I don't see any "*" expansion going
on in aQute.bnd.osgi.Builder for this case.

To be exact, I now have resource specs like: lib/=lib/jaxb-api-.*\.jar;lib:=true

Benson Margulies

unread,
Jun 29, 2016, 8:33:18 AM6/29/16
to bndtool...@googlegroups.com
OK, here's the ticket. It depends on using
maven-dependency-plugin:properties ...

-exportcontents: \
com.basistech.dp.corenlp
-includeresource: \
lib/=${javax.xml.bind:jaxb-api:jar};lib:=true, \
lib/=${javax.json:javax.json-api:jar};lib:=true, \
lib/=${com.googlecode.efficient-java-matrix-library:ejml:jar};lib:=true, \
lib/=${edu.stanford.nlp:stanford-corenlp:jar};lib:=true, \
lib/=${de.jollyday:jollyday:jar};lib:=true

Raymond Auge

unread,
Jun 29, 2016, 10:06:26 AM6/29/16
to bndtool...@googlegroups.com
It may have also depended on the regex having matched the full path of the file (my bad if that's the case).

i.e. .*jaxb-api-.*\.jar;lib:=true

- Ray

--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages