• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to run Hello World example in Eclipse with Glassfish v3 as appserver

 
L. Wei
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am reading "EJB3 In Action", and trying to run the Hello World example in the first chapter in Eclipse. I've correctly setup Glassfish v3 in Eclipse and I've created a server in the Servers console. I created a project and then copied 3 files of the chapter 1 example from the book website www.manning.com/panda

HelloUser.java


HelloUserBean.java


HelloUserClient.java


I deploy the ejb in Glassfish successfully, but when I running HelloUserClient, I got NullPointerException


I know it's because helloUser reference to null. However, is it supposed to be right for this example? or Did I miss anything else? or I can't just copy and paste the sample code into eclipse and run from there? (the book examples are run in command line). I have no clue. Please help. Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you run the application ? The HelloUser will not be injected if you execute it outside the container. Try to use Glassfish's appclient instead (there's an example here).
 
L. Wei
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:How did you run the application ? The HelloUser will not be injected if you execute it outside the container. Try to use Glassfish's appclient instead (there's an example here).


I deployed the ejb in glassfish (I thought it's in container), but I ran HelloUserClient.java as Java Application in Eclipse. I think it's wrong, but I dont know how to run HelloUserClient in Glassfish instead of Java application.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
L. Wei wrote:I dont know how to run HelloUserClient in Glassfish instead of Java application.

Use Glassfish's appclient. Check the link in my previous post.
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anybody have any exemple that use web interface?
 
André Asantos
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
L. Wei wrote:Hi, I am reading "EJB3 In Action", and trying to run the Hello World example in the first chapter in Eclipse. I've correctly setup Glassfish v3 in Eclipse and I've created a server in the Servers console. I created a project and then copied 3 files of the chapter 1 example from the book website www.manning.com/panda

HelloUser.java


HelloUserBean.java


HelloUserClient.java


I deploy the ejb in Glassfish successfully, but when I running HelloUserClient, I got NullPointerException


I know it's because helloUser reference to null. However, is it supposed to be right for this example? or Did I miss anything else? or I can't just copy and paste the sample code into eclipse and run from there? (the book examples are run in command line). I have no clue. Please help. Thanks



To skip out that code error try on:

 
Cong Yu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the HelloUserClient is not a container managed component when you run it as a java application, so the @EJB annotation doesn't work here because DI is not enabled outside the container. Instead, you must use a JNDI lookup to retrieve the EJB.

here's the example code in the main method
 
kurt hanni
Ranch Hand
Posts: 140
Eclipse IDE Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Include gf-client.jar in your classpath, then do the lookup code
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic