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;
@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;
@Stateless
public class HomeImpl implements Home{
@Override
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.org//DTD GlassFish Application Server 3.1 EJB 3.1//EN" "http://glassfish.org/dtds/glassfish-ejb-jar_3_1-1.dtd">
<glassfish-ejb-jar>
<enterprise-beans>
<ejb>
<ejb-name>HomeImpl</ejb-name>
<jndi-name>abc</jndi-name>
<pass-by-reference>true</pass-by-reference>
</ejb>
</enterprise-beans>
</glassfish-ejb-jar>
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;
System.out.println(r.sayHello("Ayaz"));
}
}
Run this class to check our EJB is deployed Sucessfully . It will give the following result in the output console.
run:
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
--------------------------------------------------------------------------------------------------------
blogs
Easy to understand,,
ReplyDeletebc
ReplyDeleteInteresting article
ReplyDeleteJava Training in Chennai
really nice and easy to implement the bean Thank you
ReplyDeletei can't able deploy the bean in server...
ReplyDeletei 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)
I get the answer after a long tragedy...............!
ReplyDeleteThank you. Tutorial was very clear :) No errors encountered :D thanks man
ReplyDeleteThanks Bro.. Keep It up this way with new post :)
ReplyDeletevery poor
ReplyDeleteHi, I do think this is a great web site. I stumbledupon it ;) I will return yet
ReplyDeleteagain 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
It's in point of fact a nice and helpful piece of info.
ReplyDeleteI'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
Definitely believe that which you stated.
ReplyDeleteYour 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
Definitely imagine that which you stated. Your favourite justification seemed to be at the web the
ReplyDeletesimplest 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
Howdy just wanted to give you a quick heads up.
ReplyDeleteThe 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
Simply desire to say your article is as surprising.
ReplyDeleteThe 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
Fine way of telling, and pleasant post to
ReplyDeleteobtain information regarding my presentation focus, which i am going to deliver
in university.
Here is my web-site beats dre (Http://Sunplanet.bplaced.net)
I'll immediately seize your rss feed as I can not in finding your
ReplyDeleteemail subscription link or e-newsletter service.
Do you have any? Please let me know so that I could subscribe.
Thanks.
Here is my site ... Cheap Dr Dre Beats
Wow, awesome blog layout! How long have you been blogging for?
ReplyDeleteyou make blogging look easy. The overall look of your web site is excellent, as well as the content!
my weblog ... Dr Dre Beats
Oh my goodness! Impressive article dude! Thank you so much, However I am encountering difficulties
ReplyDeletewith 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?
Thanks!!
Here is my webpage; Beats By Dre UK
I hardly write responses, however after browsing through a
ReplyDeletelot 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
This piece of writing will assist the internet viewers
ReplyDeletefor creating new blog or even a weblog from start
to end.
Feel free to visit my web page Fake Louis Vuitton Bags
Yesterday, while I was at work, my sister stole my apple ipad and tested to see if it
ReplyDeletecan 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
The other day, while I was at work, my cousin stole my
ReplyDeleteiphone 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
An intriguing discussion is worth comment. I believe that you should publish more about this
ReplyDeletesubject, 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
I like the valuable info you provide in your articles. I will bookmark your weblog and check again here frequently.
ReplyDeleteI am quite certain I'll learn many new stuff right here!
Best of luck for the next!
my web blog - Beats By Dre Studio (freiheitundliebe.com)
Hello There. I discovered your weblog the use of msn. This is a really well written article.
ReplyDeleteI'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
Hi there just wanted to give you a quick heads up and let you know a few of the pictures
ReplyDeletearen'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
Good day very nice blog!! Man .. Excellent .. Wonderful ..
ReplyDeleteI'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
Hey I am so excited I found your blog, I really found you by
ReplyDeleteaccident, 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
Why viewers still use to read news papers when in this technological globe
ReplyDeletethe whole thing is presented on web?
Feel free to surf to my webpage - New Balance Shoe
Hey there! I've been following your website for a
ReplyDeletelong 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
Peculiar article, just what I needed.
ReplyDeletemy blog; Beats By Dre USA
It's great that you are getting ideas from this post as well as from
ReplyDeleteour discussion made here.
Here is my web page - New Balance Online
I'm no longer certain where you are getting your info, but good topic.
ReplyDeleteI 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
Hey there, You have done an incredible job. I'll definitely digg it and personally recommend to my friends.
ReplyDeleteI am sure they will be benefited from this website.
Here is my web blog Beats By Dre Solo (http://beats-australia.rr32.com)
Hello it's me, I am also visiting this web site daily, this website is actually
ReplyDeletefastidious and the viewers are in fact sharing fastidious
thoughts.
Here is my page; Cheap Louis Vuitton Bags
I loved as much as you will receive carried out right
ReplyDeletehere. 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
Hey there fantastic blog! Does running a blog such as this require
ReplyDeletea 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
always i used to read smaller articles or reviews which also clear
ReplyDeletetheir motive, and that is also happening with this post which I am reading here.
Check out my web-site: New Balance Shoes
For newest information you have to go to see web and on web I found this
ReplyDeletewebsite as a finest website for newest updates.
Take a look at my weblog - lacrim corleone album telecharger
Hello There. I found your blog the usage of msn. This is
ReplyDeletea 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
Hi there, just wanted to say, I loved this post.
ReplyDeleteIt was funny. Keep on posting!
Have a look at my homepage; christian louboutin sale
Excellent post. Keep writing such kind of info on your site.
ReplyDeleteIm 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
I think this is one of the most vital info for me. And i am glad
ReplyDeletereading 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
When someone writes an article he/she maintains the thought of a user in his/her mind that how a user
ReplyDeletecan understand it. So that's why this article is perfect.
Thanks!
Also visit my blog post: Dr Dre Beats Studio
If you are going for finest contents like me, only visit this web
ReplyDeletesite daily as it provides quality contents, thanks
Also visit my web-site :: Louis Vuitton Handbags
For the reason that the admin of this website is working, no
ReplyDeletehesitation very quickly it will be renowned, due to its quality contents.
Here is my web-site - Christian Louboutin Canada
May I simply say what a relief to find an individual who truly knows what they are discussing over the internet.
ReplyDeleteYou 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
Heya i'm for the first time here. I found this board and I to find It
ReplyDeletereally 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
Wonderful blog! Do you have any recommendations
ReplyDeletefor 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
Wow, marvelous weblog format! How long have you been blogging for?
ReplyDeleteyou 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
WOW just what I was searching for. Came here by searching for restriction
ReplyDeleteAlso visit my blog Replica New Balance
Magnificent beat ! I would like to apprentice whilst you amend your web site, how can i subscribe for a weblog web site?
ReplyDeleteThe 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
Do you mind if I quote a few of your articles as long as I
ReplyDeleteprovide 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
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
ReplyDeleteGreat Article
ReplyDeleteJava Web Services Online Training | Web Services Course | Web Services Training Courses | Java Web Services Training in Chennai | Online Java Training | Java Training in Chennai
This comment has been removed by the author.
ReplyDeleteprogramming tutorial
ReplyDeleteThanks a lot,this article was very useful to me.
ReplyDeleteFinally found my answer here after long search :))
whoever prepared this article,i thank you.
ReplyDeletetnx a million :-)
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 http://www.maxmunus.com/contact
ReplyDeleteMaxMunus 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
MaxMunus
E-mail: nitesh@maxmunus.com
Skype id: nitesh_maxmunus
Ph:(+91) 8553912023
http://www.maxmunus.com/
perfect explanation about java programming .its very useful.thanks for your valuable information. best java training institute in chennai | java training in velachery
ReplyDeleteProgramming 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.
ReplyDeleteexcellent 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 http://crbtech.in/Java-Training/java-training-teaches-jee-application-session-beans/ which explains about jee application session.
ReplyDeleteIt’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.
ReplyDeleteDevops Course Training in Chennai |Best Devops Training Institute in Chennai
Selenium Course Training in Chennai |Best Selenium Training Institute in Chennai
Java Course Training in Chennai | Best Java Training Institute in Chennai
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.
ReplyDeleteJava Training in Chennai | J2EE Training in Chennai | Advanced Java Training in Chennai | Core Java Training in Chennai | Java Training institute in Chennai
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!
ReplyDeleteOracle Training in Chennai | Oracle Course in Chennai
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
ReplyDeleteJava training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
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 this.it's really awesome the way you have delivered your ideas.i hope you will add more content in your blog
ReplyDeleteJava Training in Chennai
Java Training in Velachery
Java Training inTambaram
Java Training in Porur
Java Training in Omr
Java Training in Annanagar
Hi there, just wanted to say, I loved this post.
ReplyDeleteIt was funny. Keep on posting!
Digital Marketing Training in Chennai
Digital Marketing Training in Velachery
Digital Marketing Training in Tambaram
Digital Marketing Training in Porur
Digital Marketing Training in Omr
Digital MarketingTraining in Annanagar
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.
ReplyDeleteSoftware 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
Thanks and that i have a dandy offer you: How Much Renovate House victorian house remodel
ReplyDelete