Top Banner
1 EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 Download the following: JDK 1.5.0.15 http://java.sun.com/javase/downloads/index_jdk5.jsp GlassFish V1 (includes JEE and Derby Database) https://glassfish.dev.java.net/public/downloadsindex.html Then go to: https://glassfish.dev.java.net/downloads/04May06.html For Windows: b48-glassfish-winnt.jar Eclipse IDE for Java EE Developers http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/releas e/europa/winter/eclipse-jee-europa-winter-win32.zip
75

EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

May 04, 2018

Download

Documents

habao
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

1

EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2

Download the following:

JDK 1.5.0.15http://java.sun.com/javase/downloads/index_jdk5.jsp

GlassFish V1 (includes JEE and Derby Database)https://glassfish.dev.java.net/public/downloadsindex.html

Then go to:https://glassfish.dev.java.net/downloads/04May06.html

For Windows:b48-glassfish-winnt.jar

Eclipse IDE for Java EE Developershttp://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/europa/winter/eclipse-jee-europa-winter-win32.zip

Page 2: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

2

Install Sun JDK 1.5.

Double-click the executable from where you downloaded the JDK:

jdk-1_5_0_15-windows-i586-p.exe

Accept the license and click Next.

Page 3: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

3

Accept the defaults and click Next.

Page 4: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

4

Watch the progress.

Page 5: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

5

Accept the defaults and click Next.

Page 6: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

6

Accept the defaults and click Next.

Page 7: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

7

Watch the progress.

Page 8: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

8

Click Finish.

Page 9: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

9

Environment Variables

Set an environment variable called JAVA_HOME to point to where you installed Java.

Update your PATH variable to include %JAVA_HOME%\bin.

Page 10: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

10

Install GlassFish V1

Copy the GlassFish jar file to your root drive, c:

Open a Command Prompt window and change to the c: drive.

Enter the following command:

java -Xmx256M -jar glassfish-installer-9.0-b48.jar

Page 11: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

11

Accept the license.

Page 12: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

12

The installation should complete.

Page 13: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

13

In the command window, change the directory to the glassfish directory.

To complete the setup, run this command:

lib\ant\bin\ant -f setup.xml

Page 14: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

14

You should see a successful build.

Page 15: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

15

Install Eclipse 3.3.2

Double-click the executable from where you downloaded Eclipse:

eclipse-jee-europa-winter-win32.zip

Click Extract all Files

Page 16: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

16

Click Next.

Page 17: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

17

Enter c:\ for the directory then click Next.

Page 18: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

18

Watch the progress.

Page 19: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

19

Click Finish.

Page 20: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

20

Create Derby Database Shortcuts

Create a Shortcut for asadmin.bat in the c:\glassfish\bin folder and copy it to theDesktop.

Page 21: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

21

Name the shortcut Start Derby.

Page 22: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

22

Add the following Target:

Page 23: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

23

Create another shortcut called Stop Derby and set the properties:

Page 24: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

24

Start the Derby Database

Double-click the Start Derby shortcut.

Page 25: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

25

Start Eclipse

Create a new Workspace

Page 26: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

26

Create a new Server

Page 27: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

27

Select Server | Installed Runtimes.

Click the Add button.

Page 28: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

28

Click the Download additional server adapters link.

Page 29: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

29

Select the GlassFish Java EE 5 Server. Click Next.

Page 30: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

30

Accept the terms and click Finish.

Click OK.

Page 31: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

31

Notice the progress in the bottom right corner of Eclipse.

Click Yes to restart Eclipse.

Page 32: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

32

After the restart, go back to Window | Preferences. Then go back to Server | InstalledRuntimes. Then click the Add button. You should see the GlassFish Servers.

Select GlassFish V1 Java EE 5 and check the checkbox to create local server. Then clickNext.

Page 33: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

33

Change the Directory by clicking the Browse button.

Page 34: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

34

Select the c:\glassfish directory. Click OK.

Page 35: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

35

Click Next.

Page 36: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

36

Click Finish.

Page 37: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

37

Click OK.

Page 38: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

38

Start the Server.

You should see the Status changed to Started.

Page 39: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

39

You should also see the log messages in the Console.

Page 40: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

40

Create a Stateless Session EJB

Create a New Project by selecting File | New | Project.

Page 41: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

41

Select EJB Project, click Next.

Page 42: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

42

Name the Project StatelessSessionProject, Add the project to an EAR, click Next.

Page 43: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

43

Change the Java Version to 5.0, click Next.

Page 44: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

44

Click Finish.

Page 45: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

45

You should see the following Projects in the Project Explorer View.

Page 46: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

46

Update the Properties of the EAR Project by selecting Properties.

Page 47: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

47

Un-check the StatelessSessionProjectClient.jar from the J2EE Module Dependences.

Page 48: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

48

Make sure that the StatelessSessionProjectClient is un-checked, click OK.

Page 49: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

49

Select Properties for the StatelessSessionProjectClient.

Page 50: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

50

Select Java Build Path | Projects tab. Then click the Add… button.

Page 51: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

51

Select the StatelessSessionProject, click OK.

Page 52: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

52

Click OK.

Page 53: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

53

Create a new Package by selecting New | Package in the StatelessSessionProject |ejbModule.

Page 54: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

54

Name the Package example, click Finish.

Page 55: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

55

Create a new Interface.

Page 56: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

56

Name the Interface IStatelessSession, click Finish.

Page 57: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

57

Add the following abstract method:

Page 58: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

58

Add the following Annotation:

Page 59: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

59

Import the package, save the Interface.

Page 60: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

60

Create a New Class.

Page 61: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

61

Name the Class StatelessSession, add the IStatelessSession Interface, click Finish.

Page 62: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

62

Add the following code:

Page 63: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

63

Add the following Annotation:

Page 64: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

64

Import the package, save the code.

Page 65: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

65

Create a New Package in the StatelessSessionProject Client | ejbModule.

Page 66: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

66

Name the Package client, click Finish.

Page 67: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

67

Create a New Class.

Page 68: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

68

Name the Class StatelessSessionClient, select the main() method stub, click Finish.

Page 69: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

69

Add the following code, imports, save the code.

Page 70: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

70

Generate the Deployment Descriptor Stub for the EAR Project.

Page 71: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

71

Add the Project EAR to the Server.

Page 72: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

72

Add the EAR, click Finish.

Page 73: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

73

You should see a successful deployment.

Page 74: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

74

Run the Client as a Java Application.

Page 75: EJB 3 Using GlassFish V1, Derby and Eclipse 3.3 3 Quick Start... · EJB 3 Using GlassFish V1, Derby and Eclipse 3.3.2 ... Un-check the StatelessSessionProjectClient.jar from the J2EE

75

You should see the following results: