Skip to main content

Using CDI with ACC in a SE environment

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
2 replies [Last post]
agoncal
Offline
Joined: 2005-04-10

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.

Do I need to do something extra ?

Thanks,

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sivakumart
Offline
Joined: 2004-01-30

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

agoncal
Offline
Joined: 2005-04-10

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 *{

*@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

> 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