Chapter 1. Welcome to EJB
Table of Contents Chapter 1. Welcome to EJB.......................................................................... 1 Section 1.1. OBJECTIVES............................................................................................................................................................... 2 Section 1.2. What is EJB all about?................................................................................................................................................. 3 Section 1.3. What does EJB really give me?................................................................................................................................... 4 Section 1.4. No more vendor lock-in!............................................................................................................................................. 5 Section 1.5. There are no Dumb Questions.................................................................................................................................... 6 Section 1.6. How does it all work?................................................................................................................................................... 7 Section 1.7. Behind the scenes........................................................................................................................................................ 8 Section 1.8. Sharpen your pencil................................................................................................................................................... 10 Section 1.9. Beans come in three flavors....................................................................................................................................... 11 Section 1.10. Session beans can be stateless or stateful................................................................................................................ 12 Section 1.11. There are no Dumb Question................................................................................................................................... 12 Section 1.12. Sharpen your pencil.................................................................................................................................................. 13 Section 1.13. Overheard at! THE TIKIBEAN LOUNGE................................................................................................................ 14 Section 1.14. Example: The Advice Guy bean................................................................................................................................ 15 Section 1.15. Five things you do to build a bean:.......................................................................................................................... 16 Section 1.16. EJB Roles and Responsibilities............................................................................................................................... 26 Section 1.17. Tutorial:.................................................................................................................................................................... 28 Section 1.18. Organize your project directory............................................................................................................................... 29 Section 1.19. Compile the two interfaces and the bean class....................................................................................................... 30 Section 1.20. Start the server......................................................................................................................................................... 31 Section 1.21. You'll see something like this................................................................................................................................... 31 Section 1.22. Start deploytool....................................................................................................................................................... 32 Section 1.23. you'll see something like this................................................................................................................................... 32 Section 1.24. Make a new Application.......................................................................................................................................... 33 Section 1.25. There are no Dumb Questions................................................................................................................................ 33 Section 1.26. Name and save the new application........................................................................................................................ 34 Section 1.27. What you'll see af ter you create and name the application................................................................................... 35 Section 1.28. Now let's make the new enterprise bean (the ejb-jar and the DD)........................................................................ 36 Section 1.29. Now we're in the really cool New Enterprise Bean Wizard.................................................................................... 37 Section 1.30. Create the new ejb-jar............................................................................................................................................. 38 Section 1.31. Add the three class files (including their package directory) to the JAR............................................................... 39 Section 1.32. Confirm that you added ONLY the package directory and the class files.............................................................. 40 Section 1.33. Make it a Stateless Session bean.............................................................................................................................. 41 Section 1.34. Tell it which of the three class files in the JAR is the actual BEAN class............................................................... 42 Section 1.35. Tell it which is the Home interface, and which is the Component interface......................................................... 43 Section 1.36. Verify everything on this screen!............................................................................................................................ 44 Section 1.37. You're done, click Finish.......................................................................................................................................... 45 Section 1.38. Meanwhile back on the main deploytool screen.................................................................................................... 46 Section 1.39. Run your bean through the deploytool verifier...................................................................................................... 47 Section 1.40. Close your eyes and click OK.................................................................................................................................. 48 Section 1.41. Whew! No failed tests.............................................................................................................................................. 49 Section 1.42. Time to Deploy........................................................................................................................................................ 50 Section 1.43. Make it Return a Client Jar...................................................................................................................................... 51 Section 1.44. Give it a name, so clients can look it up.................................................................................................................. 52 Section 1.45. Watch the progress bars go up, then celebrate....................................................................................................... 53 Section 1.46. Now you'll see the AdviceApp inside the server..................................................................................................... 54 Section 1.47. Now all we need is a client....................................................................................................................................... 55 Section 1.48. Organizing your project directory for the client..................................................................................................... 56 Section 1.49. The Client Code (AdviceClient.java)....................................................................................................................... 57 Section 1.50. Run the client!......................................................................................................................................................... 58 Section 1.51. COFFEE CRAM........................................................................................................................................................ 59 Section 1.52. COFFEE CRAM....................................................................................................................................................... 60
Chapter 1. Welcome to EJB Head First EJB™ By Bert Bates, Kathy Sierra ISBN: 0596005717 Publisher: O'Reilly Prepared for Linda Martin, Safari ID:
[email protected] Print Publication Date: 2003/10/01 User number: 896963 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.
Chapter 1. Welcome to EJB
Return to Table of Contents
Page 1
Intro to EJB
5
4 :HOFRPHWR(-%
4
(QWHUSULVH-DYD%HDQVDUHHDV\:HOODWOHDVWZKHQ\RXFRPSDUH(-%WRZKDW \RX¶GKDYHWRGRWRZULWH\RXURZQVFDODEOHWUDQVDFWLRQDOVHFXUHFRQFXUUHQWHQWHUSULVH VHUYHU,QWKLVFKDSWHUZH¶OOGHYHORSGHSOR\DQGUXQDQ(-%DSSOLFDWLRQEHIRUHGLYLQJ LQWRWKHGHWDLOV%HIRUHZH¶UHGRQHZH¶OOORRNDWWKHXVHEHQH¿WVDQGFKDUDFWHULVWLFVRI (-%DQGZH¶OOORRNEULHÀ\ DWKRZ(-%FRQWDLQHUVZRUN:H¶OOWDNHDKLJKOHYHOORRNDWWKH DUFKLWHFWXUHRI(-%DQGOHDUQDERXWWKHWKUHHEHDQW\SHV7KHPRUH\RXXQGHUVWDQGIURP WKLVFKDSWHUWKHOHVV\RX¶OOKDYHWRPHPRUL]HODWHUVRGRQ¶WVNLSLW,I\RX¶UHDQ(-%H[SHUW \RXFDQSUREDEO\JHWDZD\ZLWKMXVWDTXLFNVNLP WKLVLVDQHZFKDSWHU
Chapter 1. Welcome to EJB Head First EJB™ By Bert Bates, Kathy Sierra ISBN: 0596005717 Publisher: O'Reilly Prepared for Linda Martin, Safari ID:
[email protected] Print Publication Date: 2003/10/01 User number: 896963 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.
Chapter 1. Welcome to EJB
Return to Table of Contents
Page 2
H[DPREMHFWLYHV
(QWHUSULVH-DYDEHDQV2YHUYLHZ
2IILFLDO
:KDWLWUHDOO\PHDQV
Copyright Safari Books Online #896963 ,GHQWLI\WKHXVHEHQH¿WVDQG FKDUDFWHULVWLFVRI(QWHUSULVH -DYDEHDQVWHFKQRORJ\IRUYHUVLRQ RIWKH(-%VSHFL¿FDWLRQ
&KDSWHU
Chapter 1. Welcome to EJB Head First EJB™ By Bert Bates, Kathy Sierra ISBN: 0596005717 Publisher: O'Reilly Prepared for Linda Martin, Safari ID:
[email protected] Print Publication Date: 2003/10/01 User number: 896963 Copyright 2008, Safari Books Online, LLC. This PDF is exclusively for your use in accordance with the Safari Terms of Service. No part of it may be reproduced or transmitted in any form by any means without the prior written permission for reprints and excerpts from the publisher. Redistribution or other use that violates the fair use priviledge under U.S. copyright laws (see 17 USC107) or that otherwise violates the Safari Terms of Service is strictly prohibited.
Chapter 1. Welcome to EJB
Return to Table of Contents
Page 3
LQWURWR(-%
?PI\Q[-2*ITTIJW]\' &RPSRQHQWEDVHGGHYHORSPHQW 7ITH ENTERPRISE JAVABEANS YOU CAN DEVELOP BUILDING BLOCKS%*" COMPONENTSTHAT YOU OR SOMEONE ELSE CAN ASSEMBLE AND REASSEMBLE INTO DIFFERENT APPLICATIONS &OR