users@glassfish.java.net

Re: Using CDI with ACC in a SE environment

From: Antonio Goncalves <antonio.mailing_at_gmail.com>
Date: Wed, 5 Jan 2011 23:57:56 +0100

Hi Siva,

There's not much to it really, just an hello world to try to make it work.
First you have a Main class that injects a Hello class :


public class *Main *{

    *_at_Inject*
    Hello hello;

    public static void main(String[] args) {
        new Main().saySomething();
    }

    public void saySomething() {
        System.out.println(hello.sayHelloWorld());
    }
}

public class *Hello *{

    public String sayHelloWorld() {
        return "Hello World !!!";
    }
}

And then there is just an empty beans.xml file under the META-INF directory.
I package all this and do an appclient and get the following :

INFO: Using
com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as
the delegate
Exception in thread "main" java.lang.NullPointerException
        at
org.antoniogoncalves.cdi.bootstrapping.acc.Main.saySomething(Main.java:18)
        at
org.antoniogoncalves.cdi.bootstrapping.acc.Main.main(Main.java:14)

Antonio

2011/1/5 Sivakumar Thyagarajan <Sivakumar.Thyagarajan_at_sun.com>

> On Wednesday 05 January 2011 02:39 AM, Antonio Goncalves wrote:
>
>> Hi all,
>>
>> I want to use CDI beans in a SE environment. Using the proprietary Weld
>> API works fine (the org.jboss.weld.environment.se.StartMain class). But
>> now I want to use the Application Client Container (ACC). Correct me if
>> I'm wrong, but the ACC implements CDI, so I shouldn't need to bootstrap
>> the CDI container with the Weld StartMain class, it should be out of the
>> box, right ?
>>
>> I have a simple Main class that injects a simple Hello bean. I package
>> this classes into a .jar with a MANIFEST file declaring Main as the main
>> class plus the famous bean.xml file. Then I run appclient -jar myCDI.jar
>> but I get a NullPointerException. I'm using GF 3.0.1.
>>
>
> As per the CDI specification (Section 12.1), a container is not required to
> support application client bean archives and hence we haven't tried and
> tested bean archives in application clients.
>
> Could you share your application and the server.log error message?
>
> Thanks
> --Siva.
>
>
>> Do I need to do something extra ?
>>
>> Thanks,
>>
>> --
>> Antonio Goncalves (antonio.goncalves_at_gmail.com
>> <mailto:antonio.goncalves_at_gmail.com>)
>> Software architect
>>
>> Web site : www.antoniogoncalves.org <http://www.antoniogoncalves.org>
>> Blog: agoncal.wordpress.com <http://agoncal.wordpress.com>
>>
>> Feed: feeds2.feedburner.com/AntonioGoncalves
>> <http://feeds2.feedburner.com/AntonioGoncalves>
>> Paris JUG leader : www.parisjug.org <http://www.parisjug.org>
>> LinkedIn: www.linkedin.com/in/agoncal <http://www.linkedin.com/in/agoncal
>> >
>>
>
>


-- 
--
Antonio Goncalves (antonio.goncalves_at_gmail.com)
Software architect
Web site : www.antoniogoncalves.org
Blog: agoncal.wordpress.com
Feed: feeds2.feedburner.com/AntonioGoncalves
Paris JUG leader : www.parisjug.org
LinkedIn: www.linkedin.com/in/agoncal