Several example programs are included with the JOnAS distribution. They are located in the $JONAS_ROOT/examples/src directory. The one we will use as your first EJB application is the Session Bean (SB) example that resides in $JONAS_ROOT/examples/src/sb.
The SB example involves a Java client that accesses a Stateful Session Bean and twice invokes the buy method of the bean transaction. The client communicates with JOnAS using RMI and the configuration files should be already set so that the RMI registry will be automatically started and embedded in the same JVM as JOnAS. The figure below gives an overview of this application.
The simplest way to compile all examples is to start in the $JONAS_ROOT/examples/src directory and enter the following command line as user jonas:
ant -find build.xml install |
This command compiles all examples in the $JONAS_ROOT/examples/src directory.
Note | ||
---|---|---|
All examples assume that the current directory is $JONAS_ROOT/examples/src/ followed by the directory that contains the example. In other words, the commands entered for the SB example assume the current folder is $JONAS_ROOT/examples/src/sb, whereas the commands entered for the EB example assume the current folder is $JONAS_ROOT/examples/src/eb. To login as user jonas, first login as root, then su to user jonas, specifying /bin/bash as the shell:
|
Note | |
---|---|
This example is described in more detail in Section 5.3 Running the SB Example. |
To run this example, you will have to first start the Red Hat Application Server server and then run the Java client. Finally, at the end of the execution you should stop the Red Hat Application Server server.
Note | |
---|---|
The following example assumes that the current directory is $JONAS_ROOT/examples/src/sb. |
Here is how to proceed:
As root, start the Red Hat Application Server server:
/sbin/service jonas start |
Deploy the JAR file:
To deploy the JAR file from the command line:
jonas admin -a sb.jar |
To deploy the JAR file using the web interface:
Log into the JOnAS Administrator.
Log in with User Name jonas and Password jonas.
Click Deployments > EJB Modules (JAR).
On the sb.jar in the Deployable list box on the left side, Click Deploy, then click Apply.
A Confirm dialog appears; click Confirm.
A Result dialog appears, and the newly deployed jar is in the list.
If you click Deployments > EJB Modules (JAR) again, sb.jar will appear in the right list box, which lists the deployed jar files.
Start the Java Client:
jclient sb.ClientOp |
A successful run should output:
Create a bean Start a first transaction First request on the new bean Second request on the bean Commit the transaction Start a second transaction Rollback the transaction Request outside any transaction ClientOp OK. Exiting. |
Congratulations! You have succeeded running your first EJB application with JOnAS!
As root, stop the Red Hat Application Server server with the following command:
/sbin/service jonas stop |