How to deploy a Java EE simple application
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. May you explain me step-by-step what I should do to run this application in the ide?
package myejb;
import javax.ejb.Remote;
@Remote
public interface Hello
{
public String sayHello(String name);
}
package myejb;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Stateless(name = "HelloEJB")
@Remote({Hello.class})
public class HelloBean implements Hello
{
public HelloBean()
{
}
@Override
public String sayHello(String name)
{
return "Hello, " + name + "!";
}
}
and the Client application
package myejbclient;
import javax.ejb.EJB;
import myejb.Hello;
public class HelloClient
{
@EJB(lookup = "HelloEJB")
private static Hello hello;
public HelloClient()
{
}
public static void main(String[] args)
{
HelloClient client = new HelloClient();
client.doConversation();
}
public void doConversation()
{
System.out.println(hello.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)
请先登录再写评论。