Meaningless Drivel is fun!*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes How to run Hello World example in Eclipse with Glassfish v3 as appserver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "How to run Hello World example in Eclipse with Glassfish v3 as appserver" Watch "How to run Hello World example in Eclipse with Glassfish v3 as appserver" New topic
Author

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

L. Wei
Ranch Hand

Joined: May 01, 2008
Posts: 37
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


SCJP SE 6.0, SCWCD J2EE 5
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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).


[My Blog]
All roads lead to JavaRanch
L. Wei
Ranch Hand

Joined: May 01, 2008
Posts: 37
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Nov 23, 2009
Posts: 234
Does anybody have any exemple that use web interface?
André Asantos
Ranch Hand

Joined: Nov 23, 2009
Posts: 234
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

Joined: Feb 28, 2010
Posts: 2
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

Joined: Aug 11, 2007
Posts: 140

Include gf-client.jar in your classpath, then do the lookup code


SCJA, SCJP, SCJD, SCMAD, SCWCD, SCBCD, SCDJWS, SCEA, SOA, Spring Certified, OCP MySQL 5 Developer, PMP
 
GeeCON Prague 2014
 
subject: How to run Hello World example in Eclipse with Glassfish v3 as appserver