| Author |
How to run Hello World example in Eclipse with Glassfish v3 as appserver
|
L. Wei
Ranch Hand
Joined: May 01, 2008
Posts: 36
|
|
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é
Marshal
Joined: Nov 24, 2005
Posts: 14361
|
|
|
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).
|
[SCBCD Wall of Fame] [My Blog]
All roads lead to JavaRanch
Help Japan. Make a donation.
|
 |
L. Wei
Ranch Hand
Joined: May 01, 2008
Posts: 36
|
|
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é
Marshal
Joined: Nov 24, 2005
Posts: 14361
|
|
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é AS
|
 |
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
|
 |
 |
|
|
subject: How to run Hello World example in Eclipse with Glassfish v3 as appserver
|
|
|