Problem using, deploying an EJB

Hi All,

I have been trying to compile and run my first EJB in NetBeans. It is a very simple EJB which goes like this.

package test;

import javax.ejb.Stateless;

-

/**

*

* @author Vibhushan

*/

@Stateless

public class NewSessionBean implements NewSessionRemote, NewSessionLocal {

/** Creates a new instance of NewSessionBean */

public NewSessionBean() {

}

public String businessMethod() {

//TODO implement businessMethod

return "hi all";

}

}

-

After this I am trying to use this EJB in enterprise client, the code over there is following.

--

package applicationclient1;

import javax.ejb.EJB;

import test.NewSessionRemote;

/**

*

* @author Vibhushan

*/

public class Main {

@EJB

private static NewSessionRemote newSessionBean;

/** Creates a new instance of Main */

public Main() {

}

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

newSessionBean.businessMethod();

}

}

--

After deploying the EJB on Sun Java App Server when i try to use the Client it always throws the following exception. Please help to sove this I have tried all the wired things I even reinstalled my app server and netbeans IDE but it never worked. I hope that experts here will be able to help me

Thanks in advance

-

Jul 16, 2007 11:36:00 PM com.sun.enterprise.appclient.MainWithModuleSupport <init>

WARNING: ACC003: Application threw an exception.

java.lang.NullPointerException

at applicationclient1.Main.main(Main.java:33)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)

at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)

at com.sun.enterprise.appclient.Main.main(Main.java:180)

Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:340)

at com.sun.enterprise.appclient.Main.main(Main.java:180)

Caused by: java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:232)

at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:329)

... 1 more

Caused by: java.lang.NullPointerException

at applicationclient1.Main.main(Main.java:33)

... 7 more

Java Result: 1

[3316 byte] By [Sapana] at [2007-11-27 10:46:13]
# 1

The main reason the newSessionBean reference would be null is if the lookup of the Remote

EJB was not successful.Sometimes an IDE will generate a global JNDI name for the Remote EJB.

If it does, you need to make sure the client Remote EJB reference uses the same name.

First look at the configuration of the NewSessionBean. Is there a sun-ejb-jar.xml for it? If so, look

to see if there's a <jndi-name> assigned to this EJB. If so, update the @EJB in the Application Client

to point to the same global jndi-name using the mappedName attribute :

@EJB(mappedName="<insert-global-jndi-name>")

private static NewSessionRemote newSessionBean;

You can find more information on global JNDI names and @EJB in our EJB FAQ :

https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html

ksaksa at 2007-7-28 20:17:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Thanks a lot KSAKS, I will try it tonight

Sapana at 2007-7-28 20:17:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

I tried finding the XML file which I couldn't find so I used one of the other way where you can map the JNDI global name by "(mappedName="FooEJB")" format but it still isn't workin:(

Sapana at 2007-7-28 20:17:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

Please post the exact changes you made.

ksaksa at 2007-7-28 20:17:41 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...