Running your first EJB application

Several example programs come with the JOnAS distribution. They are located in the $JONAS_ROOT/example/src directory. The one we will use as your first EJB application is the Session Bean (SB) example that you can find in $JONAS_ROOT/example/src/sb.

This application involves a Java client that accesses a Stateful Session Bean and invokes several times the buy method of the bean inside the scope of transactions. 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. Figure 1 gives an overview of this application.

Figure 1. EB example overview

Building the example

The simplest way to compile this example is to go under $JONAS_ROOT/example/src/sb directory and to use the compile.sh shell script on Unix, or the compile.bat script on Windows.

If GNU make is installed on your machine, you can build this sb example by using the Makefile file you find in this directory. To do so just type make.

Running the example

To do a complete and clean run of this example, you will have to first start the EJB server and then run the Java client. Finally, at the end of the execution you might want to stop the EJB server. Here is how to proceed:

  1. Start the EJB server:

    • Unix platforms open a new terminal and proceed as follows:

      bash> cd $JONAS_ROOT/example/src/sb
      bash> EJBServer

    • Windows platforms open a new console window and proceed as follows:

      C:> cd %JONAS_ROOT%/example/src/sb
      C:> EJBServer

  2. Start the Java Client:

    • Unix platforms open a new terminal and proceed as follows:

      bash> cd $JONAS_ROOT/example/src/sb
      bash> . $JONAS_ROOT/config/bin/unix/config_env
      bash> java sb.ClientOp 

    • Windows platforms open a new console window and proceed as follows:

      C:> cd %JONAS_ROOT%/example/src/sb
      C:> config_env
      C:> java 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 to run you first EJB application with JOnAS !

  3. Stop the EJB server with the following command:

    JonasAdmin -s