• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 140
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Include gf-client.jar in your classpath, then do the lookup code
 
Paper beats rock. Scissors beats tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic