JONAS Deployment Guide

JONAS Home Page: http://jonas.objectweb.org

Install JONAS

To deploy ZPetStore on JONAS application server, you should firstly have JONAS installed. Check http://jonas.objectweb.org to download JONAS (version 4.3.3) and unzip it to ${jonas-root}.

It is recommended to use a directory other than ${jonas-root} to customize the JONAS configuration. Create ${jonas-base} and copy all contents from ${jonas-root}/demoserver to ${jonas-base}.

Set the following environment variables:

  • JONAS_ROOT = ${jonas-root}
  • JONAS_BASE = ${jonas-base} (if you use another directory to customize the JONAS configuration)
  • PATH = ${jonas-root}/bin/nt on Windows, or PATH = ${jonas-root}/bin/unix on Unix

Open a command window and run:

> jonas start
        

You should see following message (in your own language) displayed on the standard output:

The JOnAS Server 'jonas' version 4.3.3 is ready
        

Then check http://localhost:9000. If you can see the JONAS welcome page, JONAS is well installed.

To stop JONAS, run:

> jonas stop
        

Use MySQL as Default Data Source (Optional)

JONAS uses hypersonicSQL as its default data source. This section illustrates how to switch to the MySQL database. This step is optional.

Firstly, you should have MySQL installed and running. If you haven't got MySQL yet, check http://www.mysql.com.

Secondly, download MySQL JDBC Driver (mysql-connector-java) and unzip it to the ${mysql-jdbc-home} directory. Copy the JDBC driver mysql-connector-java-3.1.6-bin.jar from directory ${mysql-jdbc-home} to ${jonas-base}/lib/ext.

Run the mysql client program from the command line to execute some administration commands. Make sure that you are connected as a user with sufficient privileges.

Create a database called jonas for use by JONAS:

mysql> CREATE DATABASE jonas;
Query OK, 1 row affected (0.05 sec)
        

Next, create a user called jonas with password password to access the database:

mysql> GRANT ALL PRIVILEGES ON jonas.*
    -> TO jonas@localhost
    -> IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.06 sec)
        

Create (or modify if it already exists) the MySQL config properties file ${jonas-base}/conf/MySQL.properties:

#  DataSource configuration

datasource.name         jdbc_1
datasource.url          jdbc:mysql://localhost:3306/jonas
datasource.classname    com.mysql.jdbc.Driver
datasource.username     jonas
datasource.password     helloworld
datasource.mapper       rdb.mysql

#  ConnectionManager configuration

#  JDBC connection checking level.
#     0 = no special checking
#     1 = check physical connection is still open before reusing it
#     2 = try every connection before reusing it

jdbc.connchecklevel     0

#  Max age for jdbc connections
#  nb of minutes a connection can be kept in the pool

jdbc.connmaxage         1440

# Maximum time (in mn) a connection can be left busy.
# If the caller has not issued a close() during this time, the connection
# will be closed automatically.

jdbc.maxopentime        60

#  Test statement

jdbc.connteststmt       select 1

# JDBC Connection Pool size.
# Limiting the max pool size avoids errors from database.

jdbc.minconpool         10
jdbc.maxconpool         30

# Sampling period for JDBC monitoring :
# nb of seconds between 2 measures.

jdbc.samplingperiod     30

# Maximum time (in seconds) to wait for a connection in case of shortage.
# This may occur only when maxconpool is reached.

jdbc.maxwaittime        5

# Maximum of concurrent waiters for a JDBC Connection
# This may occur only when maxconpool is reached.

jdbc.maxwaiters         100
        

Edit JONAS config properties file ${jonas-base}/conf/jonas.properties and update the following lines (the original value is commented and the new value is appended on the next new line):

... ...

# Remove the "db" service:
# jonas.services  registry,jmx,jtm,db,dbm,security,resource,ejb,web,ear
jonas.services    registry,jmx,jtm,dbm,security,resource,ejb,web,ear

... ...

# Change datasource to MySQL: Not that datasource name should correspond to
# the datasource config properties file name (MySQL.properties).
# jonas.service.dbm.datasources    HSQL1
jonas.service.dbm.datasources      MySQL

# Comment all db service properties:
# jonas.service.db.class     org.objectweb.jonas.db.hsqldb.HsqlDBServiceImpl
# jonas.service.db.port      9001
# jonas.service.db.dbname    db_jonas
# jonas.service.db.user1     jonas:jonas
# jonas.service.db.user2     login:password
        

Build ZPetStore for JONAS

> cd ${zpetstore-home}
> ant
        

The above Ant command will build ZPetStore modules. If ZPetStore is built successfully, check ${zpetstore-home}/dist. You will see following files generated by Ant:

  • META-INF/application.xml
  • log4j-1.2.9.jar
  • zpetstore-commons.jar
  • zpetstore-ejb.jar
  • zpetstore-delegate.jar
  • zpetstore-store.war
  • zpetstore-cactus-ejb.war
  • jonas_genic.bat

JONAS uses the GenIC tool to generate JONAS-specific stubs and skeletons. So execute the script jonas_genic.bat:

> cd ${zpetstore-home}/dist
> ./jonas_genic.bat
        

The last step is to package all files in ${zpetstore-home}/dist into an ear file:

> cd ${zpetstore-home}/dist
> jar -cvfM zpetstore-jonas.ear .
        

The generated zpetstore-jonas.ear is now ready to be deployed on the JONAS application server.

Deploy ZPetStore on JONAS

To start JONAS and deploy zpetstore-jonas.ear on it:

> cd ${zpetstore-home}/dist

> jonas stop (if JONAS is running)
... (logging messages)
JOnAS Server 'jonas' stopped

> jonas start
... (logging messages)
The JOnAS Server 'jonas' version 4.3.3 is ready

> jonas admin -a zpetstore-jonas.ear
... (logging messages telling you that EJBs and WARs are available)
EarServiceImpl.deployEar : Ear file:${zpetstore-home}/dist/zpetstore-jonas.ear available.
        

Check http://localhost:9000/zpetstore, and that's it!