java - hk2 inhabitant files are being overwritten by uber-jar assembly -
i'm trying build executable jar (uberjar) using maven-assembly-plugin
. project uses hk2 provider dependency injection.
@service
s defined in project in of dependencies. hk2 service locator populated inhabitant files @ meta-inf/hk2-locator/default
, generated @ compile/build time. i'm using hk2-metadata-generator
.
my problem default assembly strategy jar-with-dependencies
unpacks before building jar. overwrites meta-inf/hk2-locator/default
whatever unpacked last... result, service locator cannot find services.
i have explored different solutions , looking guidance 1 best.
1. aggregate different inhabitant files during assembly
i've created assembly descriptor combines inhabitant files one:
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd"> <id>uberjar</id> <formats> <format>jar</format> </formats> <includebasedirectory>false</includebasedirectory> <containerdescriptorhandlers> <!-- remove element , following file-aggregator generates empty file --> <!-- see https://issues.apache.org/jira/browse/massembly-815 --> <containerdescriptorhandler> <handlername>metainf-services</handlername> </containerdescriptorhandler> <containerdescriptorhandler> <handlername>file-aggregator</handlername> <configuration> <filepattern>meta-inf/hk2-locator/default</filepattern> <outputpath>meta-inf/hk2-locator/default</outputpath> </configuration> </containerdescriptorhandler> </containerdescriptorhandlers> <dependencysets> <dependencyset> <unpack>true</unpack> <scope>runtime</scope> <useprojectartifact>true</useprojectartifact> </dependencyset> </dependencysets> </assembly>
apart silly bug in assembly plugin, results in combined inhabitant file looks good. however, when ask service locator dump descriptors, project's services detected several times. don't know if problem, particularly singleton services.
2. don't unpack dependencies
the idea behind leave dependencies in own jar-files, not touching meta-inf
-files. followed this post build jar, had classloading issues: dependencies not loaded despite manifest.mf
specifying jars in classpath.
this feels cleanest solution, if fix classloading.
3. use runtime discovery instead of inhabitant files
this solution promising. problem doesn't work tests using hk2-testng
(and don't understand different here).
if have advice on individual solutions or how best proceed, i'd happy hear you.
hk2 inhabitant files designed work when concatenated option #1 above works. use option when putting full modules together
Comments
Post a Comment