users@glassfish.java.net

Re: Hk2 - what is it, how to use it?

From: Sahoo <sanjeeb.sahoo_at_oracle.com>
Date: Thu, 14 Feb 2013 08:38:46 +0530

Yes, HK2 is a DI framework and is supported in OSGi environment, but it
is different from other OSGi-ready service frameworks such as
declarative services, blueprint (read Spring DM), iPOJO, etc. Its
service layer tries to be agnostic of underlying module system (like
OSGi) unlike all those ones. All those other frameworks I mentioned use
OSGi service layer, but HK2 does not. What I mean by that is neither
does HK2 dependency manager bind every HK2 service to OSGi service
registry not does it require any service to exist in OSGi service
registry. It manages its own service registry in order to maintain
isolation from module system. There is only a one-way bridge which
allows HK2 service dependencies to be resolved by OSGi services. HK2
does not require use of a maven plugin, because the maven plugin is only
used to build the metadata that's part of the module. Once the metadata
is there in the module, the runtime does not care how it was added. So,
you can even hand craft the metadata, but we discourage that. Why would
you not use the maven plugin to automatically generate the metadata?

Have you asked in Felix forum about your iPOJO issue which is where
iPOJO is developed?

HTH,
Sahoo
On Wednesday 13 February 2013 09:16 PM, Alexander Tumin wrote:
> Hello, i am looking for some Dependency Injection/Management solution
> for OSGi.
>
> At first i have tried iPOJO, but failed then to programmatically
> create an iPOJO-fied service which will be publish, binded and injected.
>
> So then i was told that hk2 sub-project of Glassfish could solve this
> task, but by just looking at hk2 website ( http://hk2.java.net/ ) you
> can't really tell what hk2 actually is.
>
> It is said there that it is an implementation of JSR-330
> specification, but what it does not say is /how/ it was implemented
> and how to use it in your OSGi container.
>
> Like, which OSGi bundles do you need to install from hk2 project in
> order to get JSR-330 annotations working, driven by hk2
> implementation, where to get them?
>
> Do you need anything but OSGi bundles for it? Like, iPOJO also
> requires a maven plugin for work, is hk2 the case too?
>
> Thanks.