I'm trying to run this simple and small application but I don't understand which is the problem and consequently how to fix it.
Here it is the code. It is very simple. One bean invoked by a client application in order to print out in the client terminal the well-known message Hello World. I have created the application by using Intellij Idea 13.0.3 IDE with Server GlassFish 4.0.0, Java JDK 8.0 and Java EE 7.
EDIT
I think I got those errors because I didn't deployed correctly my application. I have found a guide that says that after having created the client application in netbeans environment you have to execute Insert Code -> Call Enterprise Bean. Now how can I do the same thing on Intellij Idea?
package myejb;
import javax.ejb.Remote;
@Remote
public interface HelloBeanRemote
{
public String sayHello(String name);
}
package myejb;
import javax.ejb.Stateless;
@Stateless
public class HelloBean implements HelloBeanRemote
{
@Override
public String sayHello(String name)
{
return "Hello, " + name + "!";
}
}
and the Client application
package myejbclient;
import javax.ejb.EJB;
import myejb.HelloBeanRemote;
public class HelloClient
{
@EJB
private static HelloBeanRemote helloBean;
public static void main(String[] args)
{
HelloClient client = new HelloClient();
client.doConversation();
}
public void doConversation()
{
System.out.println(helloBean.sayHello("World"));
}
}
I execute glassfish to deploy the application. it is deployed correctly but when I run the client application I get this error message:
Exception in thread "main" java.lang.NullPointerException
at myejbclient.HelloClient.doConversation(HelloClient.java:27)
at myejbclient.HelloClient.main(HelloClient.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
EDIT2
The same code works like a charm in Netbeans IDE having GlassFish installed.
Netbeans IDE
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…