How to merge two jar's OSGI Service file content

Hello Team,

I have a requirement to create a fat jar .
For Example :
I have A.jar and B.jar. I would like to combine these to C.jar
I am achieving using bnd file by mentioning -buildpath : to include A and B

A.jar has content MATA-INF-services → S
B.jar has content MATA-INF-services → S

In both the jar file ‘S’ is present and content of ‘S’ file is different . When I generate fat jar (C.jar) the file ‘S’ contains only second buildpath included jar .

I would like to have file ‘S’ containing both A and B jar content. How can I achieve this ?
Any help would be appreciated

That is a hard one, but it should be doable via some macro magic:

serviceFileA: @${repo;<BsnOrGAVofA>;<VersionOfA>}!/META-INF/services/com.foo.bar.service
serviceA: ${cat;serviceFileA}

serviceFileB: @${repo;<BsnOrGAVofB>;<VersionOfB>}!/META-INF/services/com.foo.bar.service
serviceB: ${cat;serviceFileA}

content: \
 ' ${serviceA}\
${serviceB}'
-includeresource: \
	META-INF/services/com.foo.bar.service;literal='${content}'

I haven’t tested this and I’m not sure if my construct with the new line in the construct would work.

Please not that this will not work for maven, as the repo macros is not supported there.

1 Like

@juergen-albert : Thanks . I will give a try

Good idea, I tried it but it seems ‘literal’ does not interpret macros.
the file in META-INF/services/com.foo.bar.service contains “literally” the string:

${content}

@chrisrueger have you tried it without the ' around the ${content}?

Ah yes that works.

But it seems ${cat} is not interpreting the serviceA and serviceB macro.

Here is my concrete example:

serviceFileA: ${repo;org.apache.xmlgraphics:fop-core;latest}!/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageConverter

serviceA: ${cat;serviceFileA}

serviceFileB: ${repo;org.apache.xmlgraphics:xmlgraphics-commons;latest}!/META-INF/services/org.apache.xmlgraphics.image.loader.spi.ImageConverter

serviceB: ${cat;serviceFileB}

content: \

' ${serviceA}\

${serviceB}'

-includeresource: \

META-INF/services/fooservice;\

literal=${content}\

Result of the file in META-INF/services/fooservice:

${cat;serviceFileA}${cat;serviceFileB}