This tutorial guides you through running a first example EJB. Guidance is also provided for running a more complex example in which an EJB has access to a database.
You can find additional information about JOnAS configuration in Chapter 3 JOnAS Configuration.
There are several examples in the JOnAS distribution under $JONAS_ROOT/examples/src. You should run the example located in the $JONAS_ROOT/examples/src/sb/ directory first.
In this example, a Java client accesses a stateful Session Bean and calls the buy method of the bean several times inside the scope of transactions.
The easiest way to compile this example is to go to the sb directory $JONAS_ROOT/examples/src/sb/ and use the compile.sh shell script.
This a distributed example in which two processes are involved:
The JOnAS server, in which beans will be loaded
The Java client that creates instances of beans and calls business methods on it.
To run this example:
Run the JOnAS server:
service jonas start |
The following message is displayed on the standard output:
The JOnAS Server 'jonas' version-number is ready |
Make beans available to clients by loading the jar containing the sb example:
jonas admin -a sb.jar |
The following message is displayed on the standard output:
message-header: Op available |
Run the Java client in another terminal command-line window:
jclient sb.ClientOp |
If the following output displays, the first EJB application with JOnAS has run successfully:
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. |
Before ending this session, be sure to stop the JOnAS server:
service jonas stop |
These instructions are also located in the README file in the working directory.
This example demonstrates that the CLASSPATH is correctly set because, when the JOnAS server is launched, the jonas script calls the JOnAS bootstrap class.
The jclient script is being used to run the client. Note that the bean classes were found in $JONAS_ROOT/examples/classes. If this had not been the case, it would have been necessary to call the jclient script with the -cp "$JONAS_ROOT/ejbjars/sb.jar" option.
The client has succeeded in contacting the JOnAS server because the client has a distributed reference that was previously registered in the naming service. To do this, server and client use JNDI (the Java Naming and Directory Interface). The carol.properties file (which contains the JNDI configuration) is located in the $JONAS_ROOT/conf directory.
This carol.properties has the JNDI properties set to the default values.
With these default values, the registry runs on localhost on the default port (1099 for RMI/JRMP).
By default, the registry is launched in the same JVM as the JOnAS Server.