users@glassfish.java.net

RE: How to call _at_Service from plain Java class?

From: Anton Shishkov <anton.shishkov_at_gmail.com>
Date: Wed, 9 Apr 2008 16:05:26 +0300

Hi,

Ok this solves one of my problems, but how do I call a @Service from within
a JUnit test? Is there any way to make a goal "test" (similar to "run") that
will execute all of JUnit test? Because now I have to turn of the test
feature when I use "mvn install".

Anton Shishkov

-----Original Message-----
From: Sanjeeb.Sahoo_at_Sun.COM [mailto:Sanjeeb.Sahoo_at_Sun.COM] On Behalf Of
Sahoo
Sent: Wednesday, April 09, 2008 5:26 AM
To: users_at_glassfish.dev.java.net
Subject: Re: How to call @Service from plain Java class?

That is a GlassFish API which is not available in pure HK2 environment.

Thanks,
Sahoo

Marina Vatkina wrote:
> Actually, there is:
> com.sun.enterprise.v3.server.Globals.getDefaultHabitat().
>
> -marina
>
> Sahoo wrote:
>> There should have been an API like Habitat.getHabitat, but it's not
>> there. So, as a workaround, inject the Habitat to your ModuleStartup
>> service and make it available to the PlainClass. Then in the
>> PlainClass, you can write:
>>
>> habitat.getComponent(Bar.class, null);
>>
>> Thanks,
>> Sahoo
>>
>> Anton Shishkov wrote:
>>
>>>
>>> Hi all,
>>>
>>>
>>>
>>> I need to get information about how can I execute @Services from
>>> plain Java classes? Right now I am getting a NullPointerException.
>>>
>>>
>>>
>>> Example:
>>>
>>>
>>>
>>> *import* org.jvnet.hk2.annotations.Inject;
>>>
>>>
>>>
>>> *import* sahoo.hello.api.Bar;
>>>
>>>
>>>
>>> *public* *class* PlainClass {
>>>
>>>
>>>
>>> @Inject
>>>
>>> Bar bar;
>>>
>>>
>>>
>>> *public* *void* doit() {
>>>
>>> System./out/.println("PlainClass() -> bar do it ");
>>>
>>> bar.doit();
>>>
>>> }
>>>
>>>
>>>
>>> }
>>>
>>>
>>>
>>>
>>>
>>> Thank you,
>>>
>>>
>>>
>>> Anton Shishkov
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net