Saturday, July 27, 2013

Creating a Simple EJB SessionBean Using NetBeans & GlassFish Server

Hi , Today we are going to see how to create a simple EJB Stateless Session Bean using NetBeans and then we are going to deploy it in GlassFish Server and finally we will test it.

We are not going to discuss what is EJB what is Session Bean and how we have to use it etc.

So we require the following :

1.NetBeans ID
2. GlassFish Server.

Generally NetBeans comes along with GlassFish Server .While downloading NetBeans you can select this Option so that NetBeans Installer will download along with GlassFish Server.

Install the NetBeans with GlassFish Server.Once it is done we are ready to Go.

In this tutorial i am using the NetBeans 7.3 Version along with GlassFish Server 3.1.2 Version.

Now open NetBeans ID.

Step 1:

- Select : File->New Project ->Java EE - > EJB Module and click the "Next" Button.

- Give Project a Suitable Name Here i am giving "MyApp" click the "Next" Button.

- Select the Server as "GlassFish" with the version You have installed . Here i am selecting "GlassFish Server 3.1.2"

-  Select the J2EE Version what ever you have installed. Currently it is J2EE 6. and click the "Finish" Button.

You will have the Project Directory Structure something like this:

Step 2:

- Create a New Package called test under the Source Package Folder.

-  Create a new interface called "Home".under test package and add the following code.

 - This is a Remote Interface this can access from anywhere,once it is deployed in the server.

package test;
import javax.ejb.Remote;

public interface Home {
public String sayHello(String name);

Step 3:

Create a SessionBean class which implements this Interface .

RightClick on test and create New --> JavaClass--> HomeImpl

package test;

import javax.ejb.Stateless;
public class HomeImpl implements Home{

public String sayHello(String name) {
return "Welcome to EJB"+" "+name;


Step 4:

Create a GlassFish Descriptor File by

Righ Click on the Project "MyApp" and then choose New -->Other-->GlassFish-->GlassFish Descriptor and then click the "Next" button and click the "Finish " Button.

 glassfish-ejb-jar.xml file will be created under the Configuration Files Folder.

Set the JNDI Name for the HomeImpl Bean by editing the file or by clicking the TAB "EJB" and giving jndi name as "abc". 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-ejb-jar PUBLIC "-// GlassFish Application Server 3.1 EJB 3.1//EN" "">

Save the XML File.

Note : There can be only one glassfish-ejb-jar.xml file per EJB Module.

Step 5:

- Right click on the Project Node(MyApp)and select clean and Build.

- After clean and build again right click on the project node and select "Deploy".

For Both this Actions "BUILD SUCCESSFUL" Message will be displayed in the console output.Then every thing is fine and our EJB Session Bean  HomeImpl with JNDI Name "abc" is successfully Deployed.

Step 6:

RightClick on the Project Node (MyApp) and create new Class called "Main"

package test;

import java.util.Properties;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;

public class Main {

  public static void main(String arg[])throws Exception
Properties p=new Properties();
InitialContext c=new InitialContext();
Object l=c.lookup("abc");
Home r=(Home)l;


Run this class to check our EJB is deployed Sucessfully . It will give the following result in the output console.
Welcome to EJB Ayaz
BUILD SUCCESSFUL (total time: 14 seconds)

So far we have created a Stateless EJB Session Bean and deployed it in the Server and checked it through the same EJB Module , this will work since we are accessing from EJB Container locally from our EJB Module .

To access this bean remotely from another Java Component such as Web Application or Java Swing Application or Java Webservice we require the Jar files created from the "HomeImpl" Session Bean just now we created  & Server specific jars to load the Bean.

In my next Post on EJB we will see how to do this...

         Next >>                                          Index


Technology Blogs


  1. Easy to understand,,

    1. Great Article android based projects

      Java Training in Chennai Project Center in Chennai Java Training in Chennai projects for cse The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

  2. really nice and easy to implement the bean Thank you

  3. i can't able deploy the bean in server...
    i get this error msg....
    deploy?DEFAULT=/home/jec/NetBeansProjects/ejb_simulation/build/classes&name=myapp&force=true failed on GlassFish Server 4.0
    Error occurred during deployment: Exception while deploying the app [myapp] : Referencing error: this bundle has no bean of name: Homeimpl. Please see server.log for more details.
    /home/jec/NetBeansProjects/ejb_simulation/nbproject/build-impl.xml:919: The module has not been deployed.
    See the server log for details.
    BUILD FAILED (total time: 0 seconds)

  4. I get the answer after a long tragedy...............!

  5. Thank you. Tutorial was very clear :) No errors encountered :D thanks man

  6. Thanks Bro.. Keep It up this way with new post :)

  7. Hi, I do think this is a great web site. I stumbledupon it ;) I will return yet
    again since I book marked it. Money and freedom is the best way to change, may you be rich and continue to help other people.

    Here is my web-site Dre Beats headphones

  8. It's in point of fact a nice and helpful piece of info.
    I'm happy that you shared this helpful info with
    us. Please stay us informed like this. Thanks for sharing.

    Visit my page :: Dre Beats Headphones

  9. Definitely believe that which you stated.
    Your favorite justification seemed to be on the web the
    simplest thing to be aware of. I say to you, I certainly get annoyed while people think about
    worries that they just do not know about.
    You managed to hit the nail upon the top and also defined out the whole thing without having side-effects , people can take a signal.
    Will likely be back to get more. Thanks

    Here is my page Beats By Dre UK

  10. Definitely imagine that which you stated. Your favourite justification seemed to be at the web the
    simplest factor to be mindful of. I say to you, I certainly
    get irked even as folks consider concerns that they plainly do not realize about.
    You managed to hit the nail upon the highest and defined out the entire
    thing with no need side effect , people can take a signal.

    Will likely be back to get more. Thank you

    Also visit my blog post - Dr Dre Beats Headphones

  11. Howdy just wanted to give you a quick heads up.
    The text in your content seem to be running off the screen in Opera.
    I'm not sure if this is a formatting issue or something to do
    with web browser compatibility but I thought I'd post
    to let you know. The design and style look great though!

    Hope you get the problem fixed soon. Cheers

    Also visit my web-site Beats By Dre Solo

  12. Simply desire to say your article is as surprising.
    The clarity in your post is simply nice and i could assume
    you are an expert on this subject. Well with your permission allow me to grab your RSS feed to keep up to date with forthcoming post.
    Thanks a million and please carry on the gratifying work.

    Take a look at my website: dre beats headphones

  13. Fine way of telling, and pleasant post to
    obtain information regarding my presentation focus, which i am going to deliver
    in university.

    Here is my web-site beats dre (Http://

  14. I'll immediately seize your rss feed as I can not in finding your
    email subscription link or e-newsletter service.
    Do you have any? Please let me know so that I could subscribe.

    Here is my site ... Cheap Dr Dre Beats

  15. Wow, awesome blog layout! How long have you been blogging for?
    you make blogging look easy. The overall look of your web site is excellent, as well as the content!

    my weblog ... Dr Dre Beats

  16. Oh my goodness! Impressive article dude! Thank you so much, However I am encountering difficulties
    with your RSS. I don't know why I am unable to join it.

    Is there anyone else getting the same RSS issues?
    Anybody who knows the solution will you kindly respond?

    Here is my webpage; Beats By Dre UK

  17. I hardly write responses, however after browsing through a
    lot of remarks here "Creating a Simple EJB SessionBean Using NetBeans & GlassFish Server".

    I actually do have a couple of questions for you if it's allright.

    Is it only me or do a few of the comments appear like
    they are written by brain dead visitors? :-P And, if you are writing at additional sites, I'd like to keep up with everything fresh you have to post.
    Would you list of every one of all your shared pages like your twitter feed, Facebook page or linkedin profile?

    Here is my web blog: Christian Louboutin

  18. This piece of writing will assist the internet viewers
    for creating new blog or even a weblog from start
    to end.

    Feel free to visit my web page Fake Louis Vuitton Bags

  19. Yesterday, while I was at work, my sister stole my apple ipad and tested to see if it
    can survive a forty foot drop, just so she can be a youtube sensation. My apple ipad is now broken and she has 83 views.
    I know this is entirely off topic but I had to share it with someone!

    Also visit my homepage :: Dr Dre Beats USA

  20. The other day, while I was at work, my cousin stole my
    iphone and tested to see if it can survive
    a forty foot drop, just so she can be a youtube
    sensation. My apple ipad is now destroyed and she has 83 views.
    I know this is entirely off topic but I had to share
    it with someone!

    Also visit my web blog; Beats By Dre Solo

  21. An intriguing discussion is worth comment. I believe that you should publish more about this
    subject, it may not be a taboo matter but generally people do not discuss such topics.
    To the next! All the best!!

    Feel free to visit my site ... Dr Dre Beats

  22. I like the valuable info you provide in your articles. I will bookmark your weblog and check again here frequently.

    I am quite certain I'll learn many new stuff right here!

    Best of luck for the next!

    my web blog - Beats By Dre Studio (

  23. Hello There. I discovered your weblog the use of msn. This is a really well written article.
    I'll make sure to bookmark it and return to learn extra of your useful info.
    Thank you for the post. I'll definitely comeback.

    Here is my blog ... Beats Headphones

  24. Hi there just wanted to give you a quick heads up and let you know a few of the pictures
    aren't loading properly. I'm not sure why but I think its
    a linking issue. I've tried it in two different browsers and both show the same results.

    My website - Beats By Dre Cheap

  25. Good day very nice blog!! Man .. Excellent .. Wonderful ..
    I'll bookmark your blog and take the feeds additionally?

    I'm happy to find a lot of helpful information here in the publish,
    we want develop more techniques in this regard, thanks for sharing.
    . . . . .

    Also visit my site: New Balance Discount

  26. Hey I am so excited I found your blog, I really found you by
    accident, while I was searching on Bing for something
    else, Anyways I am here now and would just like to say thanks for a marvelous post and a all round exciting
    blog (I also love the theme/design), I don’t have time to go through it
    all at the minute but I have saved it and also included your RSS feeds, so when I have time I will be back to read a
    lot more, Please do keep up the great work.

    My web page: New Balance Shoes

  27. Why viewers still use to read news papers when in this technological globe
    the whole thing is presented on web?

    Feel free to surf to my webpage - New Balance Shoe

  28. Hey there! I've been following your website for a
    long time now and finally got the bravery to go ahead and give
    you a shout out from Lubbock Texas! Just wanted to
    mention keep up the good work!

    Take a look at my blog: Replica New Balance

  29. Peculiar article, just what I needed.

    my blog; Beats By Dre USA

  30. It's great that you are getting ideas from this post as well as from
    our discussion made here.

    Here is my web page - New Balance Online

  31. I'm no longer certain where you are getting your info, but good topic.
    I must spend a while learning much more or figuring out more.
    Thank you for excellent information I used to be on the lookout for
    this information for my mission.

    my web blog - christian louboutin Canada

  32. Hey there, You have done an incredible job. I'll definitely digg it and personally recommend to my friends.

    I am sure they will be benefited from this website.

    Here is my web blog Beats By Dre Solo (

  33. Hello it's me, I am also visiting this web site daily, this website is actually
    fastidious and the viewers are in fact sharing fastidious

    Here is my page; Cheap Louis Vuitton Bags

  34. I loved as much as you will receive carried out right
    here. The sketch is attractive, your authored subject matter stylish.
    nonetheless, you command get got an nervousness over that you wish be delivering the following.
    unwell unquestionably come more formerly again as exactly
    the same nearly a lot often inside case you shield this increase.

    My blog post ... Christian Louboutin Sale

  35. Hey there fantastic blog! Does running a blog such as this require
    a lot of work? I've virtually no understanding of
    coding but I had been hoping to start my own blog in the
    near future. Anyways, should you have any recommendations or tips for
    new blog owners please share. I understand this is off subject but I simply needed
    to ask. Kudos!

    Here is my website :: lacrim corleone album telecharger

  36. always i used to read smaller articles or reviews which also clear
    their motive, and that is also happening with this post which I am reading here.

    Check out my web-site: New Balance Shoes

  37. For newest information you have to go to see web and on web I found this
    website as a finest website for newest updates.

    Take a look at my weblog - lacrim corleone album telecharger

  38. Hello There. I found your blog the usage of msn. This is
    a really smartly written article. I'll be sure to bookmark
    it and return to learn more of your useful information. Thank you for the post.
    I'll certainly return.

    Feel free to visit my web page :: Christian Louboutin Cheap

  39. Hi there, just wanted to say, I loved this post.
    It was funny. Keep on posting!

    Have a look at my homepage; christian louboutin sale

  40. Excellent post. Keep writing such kind of info on your site.
    Im really impressed by it.
    Hey there, You've done a great job. I'll definitely digg it and individually recommend to my friends.
    I'm sure they'll be benefited from this web site.

    My weblog ... New Balance

  41. I think this is one of the most vital info for me. And i am glad
    reading your article. But should remark on few general things, The
    site style is great, the articles is really great : D. Good job, cheers

    Check out my webpage :: New Balance Outlet

  42. When someone writes an article he/she maintains the thought of a user in his/her mind that how a user
    can understand it. So that's why this article is perfect.

    Also visit my blog post: Dr Dre Beats Studio

  43. If you are going for finest contents like me, only visit this web
    site daily as it provides quality contents, thanks

    Also visit my web-site :: Louis Vuitton Handbags

  44. For the reason that the admin of this website is working, no
    hesitation very quickly it will be renowned, due to its quality contents.

    Here is my web-site - Christian Louboutin Canada

  45. May I simply say what a relief to find an individual who truly knows what they are discussing over the internet.
    You definitely understand how to bring an issue to light
    and make it important. More and more people really need to
    check this out and understand this side of the story. I
    was surprised you are not more popular since you definitely have the gift.

    Also visit my weblog ... Christian Louboutin Shoes

  46. Heya i'm for the first time here. I found this board and I to find It
    really useful & it helped me out a lot. I am hoping to give one thing back and aid
    others like you aided me.

    Also visit my blog; New Balance 574

  47. Wonderful blog! Do you have any recommendations
    for aspiring writers? I'm planning to start my own site soon but I'm a little lost on everything.

    Would you advise starting with a free platform like Wordpress or go for
    a paid option? There are so many choices out there that I'm totally overwhelmed ..
    Any ideas? Cheers!

    my webpage :: Christian Louboutin Sale

  48. Wow, marvelous weblog format! How long have you been blogging for?
    you made blogging glance easy. The whole glance of your
    site is wonderful, let alone the content material!

    Take a look at my site ... New Balance Outlet

  49. WOW just what I was searching for. Came here by searching for restriction

    Also visit my blog Replica New Balance

  50. Magnificent beat ! I would like to apprentice whilst you amend your web site, how can i subscribe for a weblog web site?
    The account helped me a appropriate deal. I had been tiny bit acquainted of this your broadcast provided shiny
    clear concept

    my web page ... Cheap Louis Vuitton Bags

  51. Do you mind if I quote a few of your articles as long as I
    provide credit and sources back to your weblog?
    My website is in the exact same area of interest as yours and my visitors would genuinely benefit from a lot of the information you present here.
    Please let me know if this alright with you. Cheers!

    My web-site ... Louis Vuitton Discount

  52. I have tries doing your tutorial, but in step 4 there is an error with the message "Deployment Configuration for this project is not fount. Deployment version description could not be set properly", what should I set it so that no error. thank you, I wait for your solution

  53. It is really a great work and the way in which u r sharing the knowledge is excellent.
    Thanks for helping me to understand basic concepts. As a beginner in java programming your post help me a lot.Thanks for your informative training in chennai | chennai's no.1 java training in chennai

  54. This comment has been removed by the author.

  55. Thanks a lot,this article was very useful to me.
    Finally found my answer here after long search :))

  56. whoever prepared this article,i thank you.
    tnx a million :-)

  57. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Netbeans, kindly contact us
    MaxMunus Offer World Class Virtual Instructor led training on Netbeans. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Nitesh Kumar
    Skype id: nitesh_maxmunus
    Ph:(+91) 8553912023

  58. perfect explanation about java programming .its very useful.thanks for your valuable information. best java training institute in chennai | java training in velachery

  59. Thanks a lot! You made a new blog entry to answer my question; I really appreciate your time and effort.
    java training in chennai |
    java training institutes in chennai

  60. Programming is not only an interesting profession but also an engaging process that requires patient since a single error messes the entire program. I have learned a new program today from the shared article and I will practice writing it and give back my feedback. Anyway, the author has presented the content of his or her website professionally and you can always hire our content writing services if you need Ecommerce Website Copywriting Help.

  61. excellent blog this is. Really found it useful and what you have explained here about ejb session beans is simply great work. Thanks for sharing this article. I have found similar to this on which explains about jee application session.

  62. I accept there are numerous more pleasurable open doors ahead for people that took a gander at your site.we are providing ReactJs training in Chennai.
    For more details: ReactJs training in Velachery | ReactJs training in chennai

  63. Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
    Java Training in Chennai | J2EE Training in Chennai | Advanced Java Training in Chennai | Core Java Training in Chennai | Java Training institute in Chennai

  64. I am really thankful for posting such useful information. It really made me understand lot of important concepts in the topic. Keep up the good work!
    Oracle Training in Chennai | Oracle Course in Chennai

  65. I would like to Thank for all your Efforts for making This piece of Contents...and it's my Pleasure to Visit your site and grasp the Information's...Looking Towards More about it...Advance wishes for feature updates
    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

  66. Really it is very useful for us..... the information that you have shared is really useful for everyone.Nice article i have ever read information's like's really awesome the way you have delivered your ideas.i hope you will add more content in your blog
    Java Training in Chennai

    Java Training in Velachery

    Java Training inTambaram

    Java Training in Porur

    Java Training in Omr

    Java Training in Annanagar

  67. I had read your blog and it has useful information. Please do posting useful infrmations it will really help us a lot and increase knowledge.
    Python Training in Chennai

    Python Training in Velachery

    Python Training in Tambaram

    Python Training in Porur

    Python Training in Omr
    Python Training in Annanagar

  68. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
    Software Testing Training in Chennai

    Software Testing Training in Velachery

    Software Testing Training in Tambaram

    Software Testing Training in Porur

    Software Testing Training in Omr

    Software Testing Training in Annanagar

  69. Quick up your career with Azure Training in Chennai from Infycle Technologies, the best software training institute in Chennai. A massive place to learn topmost technical courses like Medical Coding, Mobile App Development, Data Science, Big Data, BlockChain, Full Stack Development, Digital Marketing with Graphic Design, Python, and Oracle with emphasized trainers of the industry. Speak to us on 7504633633, 7502633633 to know the updated offers for your learning.