JBoss.org Community Documentation

JBoss Application Server

Installation And Getting Started Guide

JBoss Community

1. Software Versions
2. Help Contribute
1. Getting Started
1.1. Pre-Requisites
1.1.1. Hardware and Operating System Requirements
1.1.2. Configuring Your Java Environment
2. Installation Alternatives
3. Installation With Binary Download
3.1. Download and Installation
4. Installation With Source Download
4.1. Download and Installation
4.2. Installing and configuring ANT
4.3. Building with Apache ANT
5. Setting the JBOSS_HOME variable
5.1. Setting the JBOSS_HOME variable in Linux.
5.2. Setting the JBOSS_HOME variable in Windows.
6. Uninstall JBoss
7. Test your Installation
8. The JBoss Server - A Quick Tour
8.1. Server Structure
8.1.1. Server Configurations
8.1.2. Starting and Stopping the Server
8.2. The JMX Console
8.3. Hot-deployment of services in JBoss
8.4. Basic Configuration Issues
8.4.1. Core Services
8.4.2. Logging Service
8.4.3. Security Service
8.4.4. Additional Services
9. EJB3 Caveats in JBoss Application Server 5.0.0
9.1. Unimplemented features
9.2. Referencing EJB3 Session Beans from non-EJB3 Beans
10. About the Example Applications
10.1. Install Ant
11. Sample JSF-EJB3 Application
11.1. Data Model
11.2. JSF Web Pages
11.3. EJB3 Session Beans
11.4. Configuration and Packaging
11.4.1. Building The Application
11.4.2. Configuration Files
11.5. The Database
11.5.1. Creating the Database Schema
11.5.2. The HSQL Database Manager Tool
11.6. Deploying the Application
12. Using Seam
12.1. Data Model
12.2. JSF Web Pages - index.xhtml and create.xhtml
12.3. Data Access using a Session Bean
12.4. JSF Web Pages - todos.xhtml and edit.xhtml
12.5. Xml Files
12.6. Further Information
13. Using other Databases
13.1. DataSource Configuration Files
13.2. Using MySQL as the Default DataSource
13.2.1. Installing the JDBC Driver and Deploying the datasource
13.2.2. Testing the MySQL DataSource
13.3. Configuring a datasource for Oracle DB
13.3.1. Installing the JDBC Driver and Deploying the DataSource
13.3.2. Testing the Oracle DataSource
13.4. Configuring a datasource for Microsoft SQL Server 200x
13.4.1. Installing the JDBC Driver and Deploying the DataSource
13.5. Configuring JBoss Messaging Persistence Manager
13.6. Creating a JDBC client
A. Revision History
B. Further Information Sources

JBoss Application Server is the open source implementation of the Java EE suite of services. It comprises a set of offerings for enterprise customers who are looking for preconfigured profiles of JBoss Enterprise Middleware components that have been tested and certified together to provide an integrated experience. It's easy-to-use server architecture and high flexibility makes JBoss the ideal choice for users just starting out with J2EE, as well as senior architects looking for a customizable middleware platform.

Because it is Java-based, JBoss Application Server is cross-platform, easy to install and use on any operating system that supports Java. The readily available source code is a powerful learning tool to debug the server and understand it. It also gives you the flexibility to create customized versions for your personal or business use.

Installing JBoss Application Server is simple and easy. You can have it installed and running in no time. This guide will teach you to install and get started with the JBoss Application Server.

If you find a typographical error in the Installation Guide and Getting Started Guide, or if you have thought of a way to make this manual better, we would love to hear from you! Please submit a report in JIRA: http://jira.jboss.com against the project JBoss Application Server and component Docs/Installation and Getting Started Guide.

If you have a suggestion for improving the documentation, try to be as specific as possible when describing it. If you have found an error, please include the section number and some of the surrounding text so we can find it easily.


Be sure to give us your name so you can receive full credit.


This content is taken from svn.jboss.org/repos/jbossas/projects/docs/community/5 and has yet to be branched.

To access the content directly and make changes yourself:

		svn co https://svn.jboss.org/repos/jbossas/projects/docs/community/5 --username yourusername

You must have adequate disk space to install JDK and JBoss Application Server while also allowing enough space for your applications. Before installing JBoss Application Server you must have a working installation of Java. Since JBoss is 100% pure Java you can have it working on any Operating System / Platform that supports Java.

You must have a working installation of JDK 1.5 or JDK 1.6 before you install JBoss Application Server. You can install the 32-bit or 64-bit JVM as per your requirements. In this guide we will show you how to install a 32-bit Sun JDK 5.0 on a Linux Platform and Microsoft Windows Platform. But before we do that let's take a look at some of the benefits of using a 64-bit JVM.

Installing and Configuring 32-bit Sun JDK 5.0 or JDK 6.0 on Linux

  • Download the Sun JDK 5.0 or JDK 6 (Java 2 Development Kit) from Sun's website: http://java.sun.com/javase/downloads/index_jdk5.jsp for JDK 5.0 or http://java.sun.com/javase/downloads/ for JDK 6.0. Select the JDK Update <x>" (where x is the latest update number) for download and then select "RPM in self-extracting" file for Linux[1]. Read the instructions on Sun's website for installing the JDK.

  • If you do not want to use SysV service scripts you can install the "self-extracting file" for Linux instead of choosing the "RPM in self-extracting" file. In that case you can skip the next step mentioned here. But it is recommended to use the SysV service scripts for production servers.

  • Download and install the appropriate -compat RPM from JPackage here. Please ensure you choose a matching version of the -compat package to the JDK you installed.

  • Create an environment variable that points to the JDK installation directory and call it JAVA_HOME. Add $JAVA_HOME/bin to the system path to be able to run java from the command line. You can do this by adding the following lines to the .bashrc file in your home directory.

    #In this example /usr/java/jdk1.6.0_07 is the JDK installation directory.
    export JAVA_HOME=/usr/java/jdk1.6.0_07
    export PATH=$PATH:$JAVA_HOME/bin

    Set this variable for the user account doing the installation and also for the user account that will run the server.

  • If you have more than one version of JVM installed in your machine, make sure you are using the JDK1.5 or JDK1.6 installation as the default source for the java and javac executables. You can do this using the alternatives system. The alternatives system allows different versions of Java, from different sources to co-exist on your system.

    Select alternatives for java, javac and java_sdk_1.<x>

    • As root, type the following command at the shell prompt and you should see something like this:

      [root@vsr ~]$ /usr/sbin/alternatives --config java
      There are 2 programs which provide 'java'.
      Selection    Command
         1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
      *+ 2           /usr/lib/jvm/jre-1.5.0-sun/bin/java
      Enter to keep the current selection[+], or type selection number:

      Make sure the Sun version [jre-1.5.0-sun in this case] is selected (marked with a '+' in the output), or select it by entering its number as prompted.

    • Repeat the same for javac and java_sdk_1.<x>

      [root@vsr ~]$ /usr/sbin/alternatives --config javac
      There are 1 programs which provide 'javac'.
      	Selection   Command
      *+ 1           /usr/lib/jvm/java-1.5.0-sun/bin/javac
      Enter to keep the current selection[+], or type selection number:

      [root@vsr ~]$ /usr/sbin/alternatives --config java_sdk_1.5.0
      There are 1 programs which provide 'java_sdk_1.5.0'.
      	Selection   Command
      *+ 1           /usr/lib/jvm/java-1.5.0-sun
      Enter to keep the current selection[+], or type selection number:

      You should verify that java, javac and java_sdk_1.<x> all point to the same manufacturer and version.


    You can always override this step by setting the JAVA_HOME environment variable as explained in the previous step.

  • Make sure that the java executable is in your path and that you are using an appropriate version. To verify your Java environment, type java -version at the shell prompt and you should see something like this:

    [root@vsr ~]$ java -version
    java version "1.5.0_14"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
    Java HotSpot(TM) Client VM (build 1.5.0_14-b03, mixed mode, sharing)

Installing and Configuring 32-bit Sun JDK 5.0 or JDK 6.0 on Microsoft Windows

  • Download the Sun JDK 5.0 (Java 2 Development Kit) from Sun's website: http://java.sun.com/javase/downloads/index_jdk5.jsp for JDK 5.0 or http://java.sun.com/javase/downloads/ for JDK 6.0. Choose the JDK Update <x>" (where x is the latest update number) for download and then select your Windows Platform options to perform the installation.

  • Create an environment variable called JAVA_HOME that points to the JDK installation directory, for example: C:\Program Files\Java\jdk1.5.0_14\. In order to run java from the command line add the jre\bin directory to your path, for example: C:\Program Files\Java\jdk1.5.0_14\jre\bin. To do this, open the Control Panel from the Start Menu, switch to Classic View if necessary, open the System Control Panel applet, select the Advanced Tab, and click on the Environment Variables button.

[1] Make sure you choose the appropriate file for your platform.

You can install the JBoss Application Server in one of these two modes:

Three types of server configurations will be included in your installation - minimal , default , and all .

You can download the Binary zip files from http://labs.jboss.com/jbossas/downloads/.

There are two binary distributions available:

In this form of installation, simply unzip the downloaded zip file to the directory of your choice on any operating system that supports the zip format.

  • Unzip jboss-<release>.zip to extract the archive contents into the location of your choice. You can do this using the JDK jar tool (or any other ZIP extraction tool). In the example below we are assuming you downloaded the zip file to the /jboss directory.

    [usr]$ cd /jboss
    [usr]$ jar -xvf jboss-<release>.zip

  • You should now have a directory called jboss-<release>. Next you need to set your JBOSS_HOME environment variables. This is discussed in Chapter 5, Setting the JBOSS_HOME variable .

You can download the zip source file from http://labs.jboss.com/jbossas/downloads/.

  • Uncompress jboss-<release>-src.tar.gz to extract the archive contents into the location of your choice. You can do this using the tar archiving utility in Linux (or any other compatible extraction tool). In this example we are assuming your source files were copied in the /jboss folder.

    [user@localhost]$ cd /jboss
    [user@localhost]$ tar -xvf jboss-<release>-src.tar.gz

  • You should now have a directory called jboss-<release>-src.tar.gz. The next step is to build your source files. In this example we are using Apache ANT. This is discussed in the following section.

Apache Ant is a Java-based build tool. Instead of using an extended model using shell-based commands, Ant is extended using Java classes that use XML-based configuration files. The configuration files call out a target tree that executes various tasks. Each task is run by an object that implements a particular Task interface. This gives you the ability to perform cross platform builds. Please also note that if needed, Ant provides an <exec> task that allows commands to be executed based on the Operating System it is executing on. For more information on Apache ANT please click here.

You will need to build your JBoss Application Server source files before you can run the application server. Apache Ant is shipped with the JBoss Application Server source files and can be executed from the <source_directory>/tools/bin directory.

The source files can also be built using Apache Maven which is also shipped with the JBoss Application Server source files under <source_directory>/tools/maven directory. For more information about Apache Maven, please refer to http://maven.apache.org/.

Like Java, you also need to set the environment variables for Apache ANT and/or Apache Maven. The following example illustrates a desirable configuration for the .bashrc file. In the example the file is edited using the gnome text editor (gedit).

[user@localhost ~]$ gedit .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
# User specific aliases and functions
# The following are the environment variables for Java , ANT and Maven
export JAVA_HOME=/usr/java/jdk1.6.0_07/
export PATH=$PATH:$JAVA_HOME/bin

export ANT_HOME=/home/downloads/jboss-<source_directory>/tools/
export PATH=$PATH:$ANT_HOME/bin

export MAVEN_HOME=/home/downloads/jboss-<source_directory>/tools/maven

To implement the changes you've made to the .bashrc file, type the following on a terminal.

[user@localhost ~]$ source .bashrc
[user@localhost ~]$

If any errors are displayed, please check your .bashrc file for errors and ensure that all directory paths are correct.

To build the JBoss Application Server source files with Apache ANT, from a terminal change directory to where the unzipped source files are. In the following example we are assuming that the source files were copied and unzipped in the logged in user's downloads folder.

[user@localhost]$ cd /home/user/downloads/jboss-<release>-src/build
[user@localhost build]$ ls
aspects    component-matrix  docbook-support  iiop     jmx           mbeans          security    system-jmx  tools
bootstrap  connector         ejb3             j2se     jmx-remoting  messaging       server      testsuite   varia
build      console           embedded         jbossas  main          pom.xml         spring-int  thirdparty  webservices
cluster    deployment        hibernate-int    jbossmq  management    profileservice  system      tomcat

From the contents of the build directory above, you can see the build.xml file which is used by Apache ANT as a configuration file when building your source files. The next step is to perform the build using Apache ANT as illustrated below.

[user@localhost build]$ ant
[mkdir] Created dir: /jboss/jboss-<release>-src/tomcat/output/classes
[javac] Compiling 89 source files to /jboss/jboss-<release>-src/tomcat/output/classes
....content truncated
Total time: 2 seconds

A successful build will have the above message. If your build fails, please check the error log and ensure that your configuration files and environment variables are correctly set. The JBoss Application Server files are built under the build/output/jboss-<release> directory as indicated below.


At this point the JBoss Application Server source files build is a hybrid one (builds in both Ant and Maven) because it declares all JBoss dependencies as maven2 artifacts, however after the dependencies are resolved/imported the legacy ant based build is used to compile and build the distribution. The JBoss Application Server source files will change to a full maven build soon.

[user@localhost build]$ ls
build.bat        build-old.xml      build-thirdparty-old.xml  eclipse.psf       output
build-distr.xml  build-release.xml  build.xml                 etc               pom.xml
build.log        build.sh           docs                      local.properties  VersionRelease.java

[user@localhost build]$ cd output/jboss-<release>
[user@localhost build]$ ls
bin  client  docs  lib  server

The jboss-<release> directory contains your successful JBoss Application Server files. You can copy this folder to a different location or run the server from this folder after setting the JBOSS_HOME environment variable in your .bashrc file. Next you need to set your JBOSS_HOME environment variables. This is discussed in Chapter 5, Setting the JBOSS_HOME variable .

The JBoss Application Server may be uninstalled by simply deleting the JBoss Application Server's installation directory. You will also need to remove the JBOSS_HOME environment variables discussed in Chapter 5, Setting the JBOSS_HOME variable for your Linux or Windows platform.

After you have installed the JBoss Application Server, it is wise to perform a simple startup test to validate that there are no major problems with your Java VM/operating system combination. To test your installation, open the JBOSS_DIST/jboss-<release>/bin directory and execute the run.bat (for Windows) or run.sh (for Linux) script, as appropriate for your operating system.

Your output should look similar to the following (accounting for installation directory differences) and contain no error or exception messages:

[samson@dhcp-1-150 bin]$ sh run.sh 
   JBoss Bootstrap Environment
   JBOSS_HOME: /downloads/jboss-5.0.0.CR2
   JAVA: /usr/local/jdk1.6.0_07//bin/java
   JAVA_OPTS: -Dprogram.name=run.sh -server -Xms128m -Xmx512m -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.net.preferIPv4Stack=true
   CLASSPATH: /downloads/jboss-5.0.0.CR2/bin/run.jar:/usr/local/jdk1.6.0_07//lib/tools.jar
15:23:05,038 INFO  [ServerImpl] Starting JBoss (Microcontainer)...
15:23:05,042 INFO  [ServerImpl] Release ID: JBoss [Morpheus] 5.0.0.CR2 (build: SVNTag=JBoss_5_0_0_CR2 date=200809171139)	
...output truncated
15:25:18,401 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-
15:25:18,556 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-
15:25:18,620 INFO  [ServerImpl] JBoss (Microcontainer) [5.0.0.CR2 (build: SVNTag=JBoss_5_0_0_CR2 date=200809171139)] Started in 2m:13s:511ms

Now open http://localhost:8080 in your web browser. (Make sure you dont have anything else already on your machine using that port).[2] The contents of your page should look similar to the following: Figure 7.1, “Test your Installation”.

You are now ready to use the JBoss Application Server.

[2] Note that on some machines, the name localhost may not resolve properly and you may need to use the local loopback address instead.

Now that you’ve downloaded JBoss and have run the server for the first time, the next thing you will want to know is how the installation is laid out and what goes where. At first glance there seems to be a lot of stuff in there, and it’s not obvious what you need to look at and what you can safely ignore for the time being. To remedy that, we’ll explore the server directory structure, locations of the key configuration files, log files, deployment and so on. It’s worth familiarizing yourself with the layout at this stage as it will help you understand the JBoss service architecture so that you’ll be able to find your way around when it comes to deploying your own applications.

Fundamentally, the JBoss architecture consists of the JMX MBean server, the microkernel, and a set of pluggable component services - the MBeans. This makes it easy to assemble different configurations and gives you the flexibility to tailor them to meet your requirements.

You don’t have to run a large, monolithic server all the time; you can remove the components you don’t need (which can also reduce the server startup time considerably) and you can also integrate additional services into JBoss by writing your own MBeans. You certainly do not need to do this to be able to run standard Java EE 5 applications though.

You don’t need a detailed understanding of JMX to use JBoss, but it’s worth keeping a picture of this basic architecture in mind as it is central to the way JBoss works.

The JBoss Application Server ships with three different server configurations. Within the <JBoss_Home>/server directory, you will find four subdirectories: minimal, default and all - one for each server configuration. Each of these configurations provide a different set of services. The default configuration is the one used if you don’t specify another one when starting up the server.


has a minimal configuration—the bare minimum services required to start JBoss. It starts the logging service, a JNDI server and a URL deployment scanner to find new deployments. This is what you would use if you want to use JMX/JBoss to start your own services without any other Java EE 5 technologies. This is just the bare server. There is no web container, no EJB or JMS support.


is a base Java EE 5 server profile containing a default set of services. It has the most frequently used services required to deploy a Java EE application. It does not include the JAXR service, the IIOP service, or any of the clustering services.


The all configuration starts all the available services. This includes the RMI/IIOP and clustering services, which are not loaded in the default configuration.

If you want to know which services are configured in each of these instances, look at the jboss-service.xml file in the <JBoss_Home>/server/<instance-name>/conf/ directory and also the configuration files in the <JBoss_Home>/server/<instance-name>/deploy directory.

[usr@localhost <JBoss_Home>]$ls server/default/conf 
bootstrap-beans.xml       jboss-log4j.xml    login-config.xml           xmdesc
bootstrap-repo-beans.xml  jboss-minimal.xml  props
jax-ws-catalog.xml        jboss-service.xml  standardjbosscmp-jdbc.xml
 jbossjta-properties.xml   jndi.properties    standardjboss.xml

The directory server configuration you’re using, is effectively the server root while JBoss is running. It contains all the code and configuration information for the services provided by the particular server configuration. It’s where the log output goes, and it’s where you deploy your applications. Table 8.1, “Server Configuration Directory Structure” shows the directories inside the server configuration directory (<JBoss_Home>/server/<instance-name>) and their functions.

Directory Description
conf The conf directory contains the jboss-service.xml bootstrap descriptor file for a given server configuration. This defines the core services that are fixed for the lifetime of the server.
data The data directory is available for use by services that want to store content in the file system. It holds persistent data for services intended to survive a server restart. Serveral JBoss services, such as the embedded Hypersonic database instance, store data here.
deploy The deploy directory contains the hot-deployable services (those which can be added to or removed from the running server). It also contains applications for the current server configuration. You deploy your application code by placing application packages (JAR, WAR and EAR files) in the deploy directory. The directory is constantly scanned for updates, and any modified components will be re-deployed automatically.
lib This directory contains JAR files (Java libraries that should not be hot deployed) needed by this server configuration. You can add required library files here for JDBC drivers etc. All JARs in this directory are loaded into the shared classpath at startup.
log This is where the log files are written. JBoss uses the Jakarta log4j package for logging and you can also use it directly in your own applications from within the server. This may be overridden through the conf/ jboss-log4j.xml configuration file.
tmp The tmp directory is used for temporary storage by JBoss services. The deployer, for example, expands application archives in this directory.
work This directory is used by Tomcat for compilation of JSPs.

Table 8.1. Server Configuration Directory Structure

The "default" server configuration file set is located in the <JBoss_Home>/server/default directory. The following example illustrates a truncated directory structure of the jboss-as-<release> server configuration files:

[user@localhost <JBoss_Home>]$ tree
|-- bin
|-- client
|-- docs
|   |-- dtd
|   |-- examples
|   |   |-- binding-manager
|   |   |   `-- sample-bindings.xml
|   |   |-- jca
|   |   |-- jms
|   |   |-- jmx
|   |   |-- netboot
|   |   |   `-- netboot.war
|   |   `-- varia
|   |       |-- deployment-service
|   |       |-- derby-plugin.jar
|   |       |-- entity-resolver-manager
|   |       |   `-- xmlresolver-service.xml
|   |       `-- jboss-bindings.xml
|   `-- schema
|-- lib
|   |-- commons-codec.jar
|   |-- commons-httpclient.jar
|   |-- commons-logging.jar
|   |-- concurrent.jar
|   |-- endorsed
|   |   |-- serializer.jar
|   |   |-- xalan.jar
|   |   `-- xercesImpl.jar
|   |-- getopt.jar
|   |-- jboss-common.jar
|   |-- jboss-jmx.jar
|   |-- jboss-system.jar
|   |-- jboss-xml-binding.jar
|   `-- log4j-boot.jar
`-- server
|-- all
|   |-- conf
|   |   |-- jacorb.properties
|   |   |-- jboss-log4j.xml
|   |   |-- jboss-minimal.xml
|   |   |-- jboss-service.xml
|   |   |-- jbossjta-properties.xml
|   |   |-- jndi.properties
|   |   |-- login-config.xml
|   |   |-- props
|   |   |   |-- jbossws-roles.properties
|   |   |   |-- jbossws-users.properties
|   |   |   |-- jmx-console-roles.properties
|   |   |   `-- jmx-console-users.properties
|   |   |-- standardjboss.xml
|   |   |-- standardjbosscmp-jdbc.xml
|   |   `-- xmdesc
|   |-- deploy
|   |-- deploy-hasingleton
|   |   `-- jms
|   |-- farm
|   |   `-- cluster-examples-service.xml
|   `-- lib
|-- default
|   |-- conf
|   |   |-- jboss-log4j.xml
|   |   |-- jboss-minimal.xml
|   |   |-- jboss-service.xml
|   |   |-- jbossjta-properties.xml
|   |   |-- jndi.properties
|   |   |-- login-config.xml
|   |   |-- props
|   |   |   |-- jbossws-roles.properties
|   |   |   |-- jbossws-users.properties
|   |   |   |-- jmx-console-roles.properties
|   |   |   `-- jmx-console-users.properties
|   |   |-- standardjboss.xml
|   |   |-- standardjbosscmp-jdbc.xml
|   |   `-- xmdesc
|   |       |-- AttributePersistenceService-xmbean.xml
|   |       |-- ClientUserTransaction-xmbean.xml
|   |       |-- JNDIView-xmbean.xml
|   |       |-- Log4jService-xmbean.xml
|   |       |-- NamingBean-xmbean.xml
|   |       |-- NamingService-xmbean.xml
|   |       |-- TransactionManagerService-xmbean.xml
|   |       |-- org.jboss.deployment.JARDeployer-xmbean.xml
|   |       |-- org.jboss.deployment.MainDeployer-xmbean.xml
|   |       `-- org.jboss.deployment.SARDeployer-xmbean.xml
|   |-- data
|   |   |-- hypersonic
|   |   |-- jboss.identity
|   |   |-- tx-object-store
|   |   `-- xmbean-attrs
|   |-- deploy
|   |-- lib
|   |-- log
|   |   |-- boot.log
|   |   |-- server.log
|   |   `-- server.log.2008-08-09
|   |-- tmp
|   `-- work
|       `-- jboss.web
|           `-- localhost
`-- minimal
|-- conf
|   |-- jboss-log4j.xml
|   |-- jboss-service.xml
|   |-- jndi.properties
|   `-- xmdesc
|       |-- NamingBean-xmbean.xml
|       `-- NamingService-xmbean.xml
|-- deploy
`-- lib
|-- jboss-management.jar
|-- jboss-minimal.jar
|-- jnpserver.jar
            `-- log4j.jar

The files in the deploy directory are explained in the following table.

File Description
bsh-deployer.xml This file configures the bean shell deployer, which deploys bean shell scripts as JBoss services.
cache-invalidation-service.xml This is a service that allows for custom invalidation of the EJB caches via JMS notifications. It is disabled by default.
client-deployer-service.xml This is a service that provides support for Java EE application clients. It manages the java:comp/env enterprise naming context for client applications based on the application-client.xml descriptor.
ear-deployer.xml The EAR deployer is the service responsible for deploying Java EE EAR files.
ejb-deployer.xml The EJB deployer is the service responsible for deploying JEE EJB JAR files.
hsqldb-ds.xml hsqldb-ds.xml configures the Hypersonic embedded database service configuration file. It sets up the embedded database and related connection factories.
http-invoker.sar http-invoker.sar contains the detached invoker that supports RMI over HTTP. It also contains the proxy bindings for accessing JNDI over HTTP.
jboss-aop-jdk50.deployer This service configures the AspectManagerService and deploys JBoss AOP applications.
jboss-bean.deployer jboss-bean.deployer provides the JBoss microcontainer, which deploys POJO services wrapped in .beans files.
jboss-ha-local-jdbc.rar jboss-ha-local-jdbc.rar is an experimental version of jboss-local-jdbc.rar that supports datasource failover.
jboss-ha-xa-jdbc.rar jboss-ha-xa-jdbc.rar is an experimental version of jboss-xa-jdbc.rar that supports datasource failover.
jboss-local-jdbc.rar jboss-local-jdbc.rar is a JCA resource adaptor that implements the JCA ManagedConnectionFactory interface for JDBC drivers that support the DataSource interface but not JCA.
jboss-xa-jdbc.rar jboss-xa-jdbc.rar is a JCA resource adaptor that implements the JCA ManagedConnectionFactory interface for JDBC drivers that support the XADataSource interface.
jbossjca-service.xml jbossjca-service.xml is the application server implementation of the JCA specification. It provides the connection management facilities for integrating resource adaptors into the JBoss server.
jboss-web.deployer The jboss-web.deployer directory provides the Tomcat servlet engine.
jbossws.sar jbossws.sar provides JEE web services support.
messaging/destinations-service.xml destinations-service.xml configures a number of Messaging queues and topics used by the Messaging unit tests.
messaging/messaging-service.xml The messaging-service.xml file configures the core JBoss Messaging service.
jmx-console.war The jmx-console.war directory provides the JMX Console. The JMX Console provides a simple web interface for managing the MBean server.
jmx-invoker-service.sar jmx-invoker-service.sar is an unpacked MBean service archive that exposes a subset of the JMX MBeanServer interface methods as an RMI interface to enable remote access to the JMX core functionality. This is similar to the legacy jmx-rmi-adaptor.sar, with the difference that the transport is handled by the detached invoker architecture.
jsr-88-service.xml jsr-88-service.xml provides the JSR 88 remote deployment service.
mail-ra.rar mail-ra.rar is a resource adaptor that provides a JavaMail connector.
mail-service.xml The mail-service.xml file is an MBean service descriptor that provides JavaMail sessions for use inside the JBoss server.
management/console-mgr.sar console-mgr.sar provides the Web Console. It is a web application/applet that provides a richer view of the JMX server management data than the JMX console. You may view the console using the URL http://localhost:8080/web-console/.
monitoring-service.xml The monitoring-service.xml file configures alert monitors like the console listener and email listener used by JMX notifications.
properties-service.xml The properties-service.xml file is an MBean service descriptor that allows for customization of the JavaBeans PropertyEditors as well as the definition of system properties.
scheduler-service.xml The scheduler-service.xml and schedule-manager-service.xml files are MBean service descriptors that provide a scheduling type of service.
sqlexception-service.xml The sqlexception-service.xml file is an MBean service descriptor for the handling of vendor specific SQLExceptions.
uuid-key-generator.sar The uuid-key-generator.sar service provides a UUID-based key generation facility.

Table 8.3. Contents of "deploy" directory

Move to JBOSS_DIST/jboss-as/bin directory and execute the run.bat (for Windows) or run.sh (for Linux) script, as appropriate for your operating system.

Remote connection to the JBoss AS server

JBoss AS now binds its services to localhost ( by default, instead of binding to all available interfaces ( This was primarily done for security reasons because of concerns of users going to production without having secured their servers properly. To enable remote access by binding JBoss services to a particular interface, simply run jboss with the -b option. To bind to all available interfaces and re-enable the legacy behaviour use -b In any case, be aware you still need to secure your server properly.

For more information including setting up multiple JBoss server instances on one machine and hosting multiple domains with JBoss, please refer to the Administration and Configuration Guide. Some examples on binding are shipped in <JBOSS_HOME>/docs/examples/binding-manager/sample-bindings.xml.

On starting your server, your screen output should look like the following (accounting for installation directory differences) and contain no error or exception messages:

[user@mypc bin]$ ./run.sh 

  JBoss Bootstrap Environment

  JBOSS_HOME: /home/user/jboss-as-version/jboss-as

  JAVA: java

  JAVA_OPTS: -Dprogram.name=run.sh -server -Xms1503m -Xmx1503m -Dsun.rmi.dgc.client.
gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djava.net.preferIPv4Stack=true

  CLASSPATH: /home/user/jboss-as-version/jboss-as/bin/run.jar


More options for the JBoss AS run script are discussed in Section, “Start the Server With Alternate Configuration” below.


Note that there is no "Server Started" message shown at the console when the server is started using the production profile, which is the default profile used when no other is specified. This message may be observed in the server.log file located in the server/production/log subdirectory.

You can configure the server to run as a service under Microsoft Windows, and configure it to start automatically if desired.

Download the JavaService package from http://forge.objectweb.org/projects/javaservice/.

Unzip the package and use the JBossInstall.bat file to install the JBoss service. You must set the JAVA_HOME and JBOSS_HOME environment variables to point to the jdk and jboss-as directories before running JBossInstall.bat. Run JBossInstall.bat with the following syntax:

                         [-auto | -manual]

Where <depends> is the name of any service that the JBoss AS server depends on, such as the mysql database service.

Once the service is installed the server can be started by using the command net start JBoss, and stopped with the command net stop JBoss.

Please refer to the documentation included in the JavaService package for further information.

When the JBoss Server is running, you can get a live view of the server by going to the JMX console application at http://localhost:8080/jmx-console. You should see something similar to Figure 8.1, “View of the JMX Management Console Web Application”.

The JMX Console is the JBoss Management Console which provides a raw view of the JMX MBeans which make up the server. They can provide a lot of information about the running server and allow you to modify its configuration, start and stop components and so on.

For example, find the service=JNDIView link and click on it. This particular MBean provides a service to allow you to view the structure of the JNDI namespaces within the server. Now find the operation called list near the bottom of the MBean view page and click the invoke button. The operation returns a view of the current names bound into the JNDI tree, which is very useful when you start deploying your own applications and want to know why you can’t resolve a particular EJB name.

Look at some of the other MBeans and their listed operations; try changing some of the configuration attributes and see what happens. With a very few exceptions, none of the changes made through the console are persistent. The original configuration will be reloaded when you restart JBoss, so you can experiment freely without doing any permanent damage.

Now that we have examined the JBoss server, we will take a look at some of the main configuration files and what they are used for. All paths are relative to the server configuration directory (server/production, for example).

In JBoss log4j is used for logging. If you are not familiar with the log4j package and would like to use it in your applications, you can read more about it at the Jakarta web site (http://jakarta.apache.org/log4j/).

Logging is controlled from a central conf/jboss-log4j.xml file. This file defines a set of appenders specifying the log files, what categories of messages should go there, the message format and the level of filtering. By default, JBoss produces output to both the console and a log file (log/server.log).

There are 5 basic log levels used: DEBUG, INFO, WARN, ERROR and FATAL. The logging threshold on the console is INFO, which means that you will see informational messages, warning messages and error messages on the console but not general debug messages. In contrast, there is no threshold set for the server.log file, so all generated logging messages will be logged there.

If things are going wrong and there doesn’t seem to be any useful information in the console, always check the server.log file to see if there are any debug messages which might help you to track down the problem. However, be aware that just because the logging threshold allows debug messages to be displayed, that doesn't mean that all of JBoss will produce detailed debug information for the log file. You will also have to boost the logging limits set for individual categories. Take the following category for example.

<!-- Limit JBoss categories to INFO --> 
<category name="org.jboss"> 
    <priority value="

This limits the level of logging to INFO for all JBoss classes, apart from those which have more specific overrides provided. If you were to change this to DEBUG, it would produce much more detailed logging output.

As another example, let’s say you wanted to set the output from the container-managed persistence engine to DEBUG level and to redirect it to a separate file, cmp.log, in order to analyze the generated SQL commands. You would add the following code to the conf/jboss-log4j.xml file:

<appender name="CMP" class="org.jboss.logging.appender.RollingFileAppender"> 
    <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/> 
    <param name="File" value="${jboss.server.home.dir}/log/cmp.log"/> 
    <param name="Append" value="false"/> 
    <param name="MaxFileSize" value="500KB"/> 
    <param name="MaxBackupIndex" value="1"/> 
    <layout class="org.apache.log4j.PatternLayout"> 
        <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/> 
<category name="org.jboss.ejb.plugins.cmp"> 
    <priority value="DEBUG" /> 
    <appender-ref ref="CMP"/> 

This creates a new file appender and specifies that it should be used by the logger (or category) for the package org.jboss.ejb.plugins.cmp.

The file appender is set up to produce a new log file every day rather than producing a new one every time you restart the server or writing to a single file indefinitely. The current log file is cmp.log. Older files have the date they were written added to their filenames. Please note that the log directory also contains HTTP request logs which are produced by the web container.

The security domain information is stored in the file conf/login-config.xml as a list of named security domains, each of which specifies a number of JAAS [3] login modules which are used for authentication purposes in that domain. When you want to use security in an application, you specify the name of the domain you want to use in the application’s JBoss-specific deployment descriptors, jboss.xml (used in defining jboss specific configurations for an application) and/or jboss-web.xml (used in defining jboss for a Web application. We'll quickly look at how to do this to secure the JMX Console application which ships with JBoss.

Almost every aspect of the JBoss server can be controlled through the JMX Console, so it is important to make sure that, at the very least, the application is password protected. Otherwise, any remote user could completely control your server. To protect it, we will add a security domain to cover the application. This can be done in the jboss-web.xml file for the JMX Console, which can be found in deploy/jmx-console.war/WEB-INF/ directory. Uncomment the security-domain in that file, as shown below.


This links the security domain to the web application, but it doesn't tell the web application what security policy to enforce, what URLs are we trying to protect, and who is allowed to access them. To configure this, go to the web.xml file in the same directory and uncomment the security-constraint that is already there. This security constraint will require a valid user name and password for a user in the JBossAdmin group.

   A security constraint that restricts access to the HTML JMX console
   to users with the role JBossAdmin. Edit the roles to what you want and
   uncomment the WEB-INF/jboss-web.xml/security-domain element to enable
   secured access to the HTML JMX console.
            An example security config that only allows users with the
            role JBossAdmin to access the HTML JMX console web application

That's great, but where do the user names and passwords come from? They come from the jmx-console security domain we linked the application to. We have provided the configuration for this in the conf/login-config.xml.

<application-policy name="jmx-console">
        <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
            <module-option name="usersProperties">
            <module-option name="rolesProperties">

This configuration uses a simple file based security policy. The configuration files are found in the conf/props directory of your server configuration. The usernames and passwords are stored in the conf/props/jmx-console-users.properties file and take the form "username=password". To assign a user to the JBossAdmin group add "username=JBossAdmin" to the jmx-console-roles.properties file (additional roles on that username can be added comma separated). The existing file creates an admin user with the password admin. For security, please either remove the user or change the password to a stronger one.

JBoss will re-deploy the JMX Console whenever you update its web.xml. You can check the server console to verify that JBoss has seen your changes. If you have configured everything correctly and re-deployed the application, the next time you try to access the JMX Console, it will ask you for a name and password. [4]

The JMX Console isn't the only web based management interface to JBoss. There is also the Web Console. Although it's a Java applet, the corresponding web application can be secured in the same way as the JMX Console. The Web Console is in the file deploy/management/console-mgr.sar/web-console.war.. The only difference is that the Web Console is provided as a simple WAR file instead of using the exploded directory structure that the JMX Console did. The only real difference between the two is that editing the files inside the WAR file is a bit more cumbersome.

[3] The Java Authentication and Authorization Service. JBoss uses JAAS to provide pluggable authentication modules. You can use the ones that are provided or write your own if you have more specific requirements.

[4] Since the username and password are session variables in the web browser you may need to restart your browser to use the login dialog window.

There are a number of implementation features that you should be aware of when developing applications for JBoss Application Server 5.0.0.

In this guide, we make use of a simple web application to show the use of JSF-EJB3 components. We then illustrate how to use Seam to integrate the JSF and EJB3 components. The example applications (source code) come with this guide and you can find them located in the JBOSS_DIST/doc/examples directory. You can also download the sample applications from http://www.redhat.com/docs/manuals/jboss. We use two examples in this book:

  • A simple "TODO" application to create, view and edit tasks - implemented using JSF and EJB3;

  • The same application using the SEAM framework.

If you installed the documentation on your hard drive, then the first example can be found in the JBOSS_DIST/doc/examples/jsfejb3 directory (if you download the examples the path is: gettingstarted/jsfejb3). We will see how to build this example using the build.xml file present here and also how to deploy the application. We will also cover in detail the workings of the .java, .xml and .properties files.

The second example used in this guide can be found in the JBOSS_DIST/doc/examples/seamejb3 directory. Using a simple "TODO" application we will illustrate how Seam ties together the database, the web interface and the EJB3 business logic in a web application. We will use the build.xml file present here to compile and build our Seam application.

Within the JBOSS_DIST/doc/examples/<seamejb3|jsfejb3> directory, you will find the following sub-directories:

  • src : contains the Java source code files.

  • view : contains the web pages.

  • resources : contains all the configuration files used.

To compile and package the examples, you must have Apache Ant 1.6+ installed in your machine. You can download it from http://ant.apache.org and have it installed in few steps:

  • Unzip the downloaded file to the directory of your choice.

  • Create an environment variable called ANT_HOME pointing to the Ant installation directory. You can do this by adding the following line to your .bashrc file (substituting with the actual location of the ant directory on your system):

    export ANT_HOME=/home/user/apache-ant-1.7.0

    On Windows you do this by opening the Control Panel from the Start Menu, switching it to classic view if necessary, then opening System/Advanced/Environment Variables. Create a new variable, call it ANT_HOME and set it to be the ant directory.

  • Add $ANT_HOME/bin to the system path to be able to run ant from the command line. You can do this by adding the following line to your .bashrc file:

    export PATH=$PATH:$ANT_HOME/bin

    On Windows you do this by opening the Control Panel from the Start Menu, switching it to classic view if necessary, then editing the PATH environment variable found in System/Advanced/Environment Variables/System Variables/Path. Add a semicolon and the path to the ant bin directory.

  • Verify your Ant installation. To do this type ant -version at the command prompt. Your output should look something like this:

    Apache Ant version 1.7.0 compiled on December 13 2006

We use a simple "TODO" application to show how JSF and EJB3 work together in a web application. The "TODO" application works like this: You can create a new 'todo' task item using the "Create" web form. Each 'todo' item has a 'title' and a 'description'. When you submit the form, the application saves your task to a relational database. Using the application, you can view all 'todo' items, edit/delete an existing 'todo' item and update the task in the database.

The sample application comprises the following components:

  • Entity objects - These objects represent the data model; the properties in the object are mapped to column values in relational database tables.

  • JSF web pages - The web interface used to capture input data and display result data. The data fields on these web pages are mapped to the data model via the JSF Expression Language (EL).

  • EJB3 Session Bean - This is where the functionality is implemented. We make use of a Stateless Session Bean.

In this section we will show you how the web interface is defined using JSF pages. We will also see how the data model is mapped to the web form using JSF EL. Using the #{...} notation to reference Java objects is called JSF EL (JSF Expression Language). Lets take a look at the pages used in our application:


We have used XHTML pages in the sample applications because we recommend using Facelets instead of JSP to render JSF view pages.

EJB 3.0 is one of the major improvements introduced with Java EE 5.0. It aims at reducing the complexity of older versions of EJB and simplifies Enterprise Java development and deployment. You will notice that to declare a class as a 'Session Bean' you simply have to annotate it. Using annotations eliminates the complexity involved with too many deployment descriptors. Also the only interface an EJB3 Session Bean requires is a business interface that declares all the business methods that must be implemented by the bean.

We will explore the two important source files associated with the Bean implementation in our application: TodoDaoInt.java and TodoDao.java.

  • Business interface : TodoDaoInt.java

    We define here the methods that need to be implemented by the bean implementation class. Basically, the business methods that will be used in our application are defined here.

    public interface TodoDaoInt {
      public void persist (Todo todo);
      public void delete (Todo todo);
      public void update (Todo todo);
      public List <Todo> findTodos ();
      public Todo findTodo (String id);

  • Stateless Session Bean : TodoDao.java

    The @Stateless annotation marks the bean as a stateless session bean. In this class, we need to access the Entity bean Todo defined earlier. For this we need an EntityManager. The @PersistenceContext annotation tells the JBoss Server to inject an entity manager during deployment.

    public class TodoDao implements TodoDaoInt {
      private EntityManager em;
      public void persist (Todo todo) {
        em.persist (todo);
      public void delete (Todo todo) {
        Todo t = em.merge (todo);
        em.remove( t );
      public void update (Todo todo) {
        em.merge (todo);
      public List <Todo> findTodos () {
        return (List <Todo>) em.createQuery("select t from Todo t")
      public Todo findTodo (String id) {
        return (Todo) em.find(Todo.class, Long.parseLong(id));

We will build the sample application using Ant and explore the configuration and packaging details. Please install Ant if currently not installed on your computer.

Let's look at building the example application and then explore the configuration files in detail.

In Chapter 10, About the Example Applications , we looked at the directory structure of the jsfejb3 sample application. At the command line, go to the jsfejb3 directory. There you will see a build.xml file. This is our Ant build script for compiling and packaging the archives. To build the application, you need to first of all edit the build.xml file and edit the value of jboss-dist to reflect the location where the JBoss Application Server is installed. Once you have done this, just type the command ant and your output should look like this:

[user@localhost jsfejb3]$ ant
Buildfile: build.xml

    [mkdir] Created dir: /jboss/gettingstarted/jsfejb3/build/classes
    [javac] Compiling 4 source files to /home/user/Desktop/gettingstarted/jsfejb3/build/classes
    [javac] Note: /jboss/gettingstarted/jsfejb3/src/TodoDao.java uses unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.

    [mkdir] Created dir: /jboss/gettingstarted/jsfejb3/build/jars
      [war] Building war: /jboss/gettingstarted/jsfejb3/build/jars/app.war

      [jar] Building jar: /jboss/gettingstarted/jsfejb3/build/jars/app.jar

      [ear] Building ear: /jboss/gettingstarted/jsfejb3/build/jars/jsfejb3.ear


Total time: 3 seconds

If you get the BUILD SUCCESSFUL message, you will find a newly created build directory with 2 sub-directories in it:

  • classes : containing the compiled class files.

  • jars : containing three archives - app.jar, app.war and jsfejb3.ear.

    • app.jar : EJB code and descriptors.

    • app.war : web application which provides the front end to allow users to interact with the business components (the EJBs). The web source (HTML, images etc.) contained in the jsfejb3/view directory is added unmodified to this archive. The Ant task also adds the WEB-INF directory that contains the files which aren’t meant to be directly accessed by a web browser but are still part of the web application. These include the deployment descriptors (web.xml) and extra jars required by the web application.

    • jsfejb3.ear : The EAR file is the complete application, containing the EJB modules and the web module. It also contains an additional descriptor, application.xml. It is also possible to deploy EJBs and web application modules individually but the EAR provides a convenient single unit.

Now that we have built the application, lets take a closer look at some of the important Configuration files. We have built the final archive ready for deployment - jsfejb3.ear. The contents of your EAR file should look like this:

|+ app.jar   // contains the EJB code
    |+ import.sql
    |+ Todo.class
    |+ TodoDao.class
    |+ TodoDaoInt.class
    |+ META-INF
        |+ persistence.xml
|+ app.war   // contains web UI
    |+ index.html
    |+ index.xhtml
    |+ create.xhtml
    |+ edit.xhtml
    |+ todos.xhtml
    |+ TodoBean.class
    |+ style.css
    |+ META-INF
    |+ WEB-INF
       |+ faces-config.xml
       |+ navigation.xml
       |+ web.xml
|+ META-INF  // contains the descriptors
    |+ application.xml
    |+ jboss-app.xml
  • application.xml: This file lists the JAR files in the EAR (in our case app.jar) and tells the JBoss server what files to look for and where. The root URL for the application is also specified in this file as 'context-root'.

      <display-name>Sample Todo</display-name>

  • jboss-app.xml: Every EAR application should specify a unique string name for the class loader. In our case, we use the application name 'jsfejb3' as the class loader name.


  • app.jar: This contains EJB3 Session Bean and Entity Bean classes and the related configuration files. In addition, the persistence.xml file configures the back-end data source (in our case the default HSQL database) for the EntityManager.

       <persistence-unit name="helloworld">
             <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
             <property name="hibernate.hbm2ddl.auto" value="create-drop"/>

  • app.war: This contains the Web UI files packaged according to the Web Application aRchive (WAR) specification. It contains all the web pages and the required configuration files. The web.xml file is an important file for all JAVA EE web applications. It is the web deployment descriptor file. The faces-config.xml file is the configuration file for JSF. The navigation.xml file contains the rules for JSF page navigation.


Deploying an application in JBoss is simple and easy. You just have to copy the EAR file to the deploy directory in the 'server configuration' directory of your choice. Here, we will deploy it to the 'default' configuration, so we copy the EAR file to the JBOSS_DIST/jboss-as/server/default/deploy directory.

You should see something close to the following output from the server:

15:32:23,997 INFO  [EARDeployer] Init J2EE application: file:/jboss/jboss-as-5.0.0<release>/server/default/deploy/jsfejb3.ear
15:32:24,212 INFO  [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.
15:32:24,213 INFO  [JmxKernelAbstraction] installing MBean: persistence.units:ear=
jsfejb3.ear,jar=app.jar,unitName=helloworld with dependencies:
15:32:24,213 INFO  [JmxKernelAbstraction]       jboss.jca:name=DefaultDS,service=
15:32:24,275 INFO  [PersistenceUnitDeployment] Starting persistence unit persistence.
15:32:24,392 INFO  [Ejb3Configuration] found EJB3 Entity bean: Todo
15:32:24,450 WARN  [Ejb3Configuration] Persistence provider caller does not implements 
the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null.
15:32:24,512 INFO  [Configuration] Reading mappings from resource : META-INF/orm.xml
15:32:24,512 INFO  [Ejb3Configuration] [PersistenceUnit: helloworld] no META-INF/orm.xml 
15:32:24,585 INFO  [AnnotationBinder] Binding entity from annotated class: Todo
15:32:24,586 INFO  [EntityBinder] Bind entity Todo on table Todo
15:32:26,311 INFO  [SchemaExport] Running hbm2ddl schema export
15:32:26,312 INFO  [SchemaExport] exporting generated schema to database
15:32:26,314 INFO  [SchemaExport] Executing import script: /import.sql
15:32:26,418 INFO  [SchemaExport] schema export complete
15:32:26,454 INFO  [NamingHelper] JNDI InitialContext properties:{java.naming.factory.
initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.
15:32:26,484 INFO  [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.
15:32:26,485 INFO  [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=jsfejb3.ear,
jar=app.jar,name=TodoDao,service=EJB3 with dependencies:
15:32:26,513 INFO  [JmxKernelAbstraction]       persistence.units:ear=jsfejb3.ear,
15:32:26,557 INFO  [EJBContainer] STARTED EJB: TodoDao ejbName: TodoDao
15:32:26,596 INFO  [EJB3Deployer] Deployed: file:/jboss/jboss-as-5.0.0<release>
15:32:26,625 INFO  [TomcatDeployer] deploy, ctxPath=/jsfejb3, warUrl=.../tmp/deploy/
15:32:26,914 INFO  [EARDeployer] Started J2EE application: file:/jboss/jboss-as-5.0.0<release>/server/default/deploy/jsfejb3.ear

If there are any errors or exceptions, make a note of the error message. Check that the EAR is complete and inspect the WAR file and the EJB jar files to make sure they contain all the necessary components (classes, descriptors etc.).

You can safely redeploy the application if it is already deployed. To undeploy it you just have to remove the archive from the deploy directory. There’s no need to restart the server in either case. If everything seems to have gone OK, then point your browser at the application URL.


You will be forwarded to the application main page. Figure 11.5, “Sample TODO” shows the sample application in action.

JBoss Seam is a framework that provides the glue between the new EJB3 and JSF frameworks that are part of the Java EE 5.0 standard. In fact, the name Seam refers to the seamless manner in which it enables developers to use these two frameworks in an integrated manner. Seam automates many of the common tasks, and makes extensive use of annotations to reduce the amount of xml code that needs to be written. The overall effect is to significantly reduce the total amount of coding that needs to be done.

If you are new to Seam, you can find more introductory information from the following url and book:

We have included two versions of the example application, one coded using EJB3 / JSF without using Seam, and one using Seam, to demonstrate clearly the difference in application development using the Seam framework.

Let's start off our examination of the Seam implementation in the same way, by examining how the Data Model is implemented. This is done in the Todo.java file.

public class Todo implements Serializable {

  private long id;
  private String title;
  private String description;

  public Todo () {
    title ="";
    description ="";

  @Id @GeneratedValue
  public long getId() { return id;}
  public void setId(long id) { this.id = id; }

  public String getTitle() { return title; }
  public void setTitle(String title) {this.title = title;}

  public String getDescription() { return description; }
  public void setDescription(String description) {
    this.description = description;


The @Entity annotation defines the class as an EJB3 entity bean, and tells the container to map the Todo class to a relational database table. Each property of the class will become a column in the table. Each instance of the class will become a row in this table. Since we have not used the @Table annotation, Seam's "configuration by exception" default will name the table after the class.

@Entity and @Table are both EJB3 annotations, and are not specific to Seam. It is possible to use Seam completely with POJOs (Plain Old Java Objects) without any EJB3-specific annotations. However, EJB3 brings a lot of advantages to the table, including container managed security, message-driven components, transaction and component level persistence context, and @PersistenceContext injection, which we will encounter a little further on.

The @Name annotation is specific to Seam, and defines the string name for Seam to use to register the Entity Bean. This will be the default name for the relational database table. Each component in a Seam application must have a unique name. In the other components in the Seam framework, such as JSF web pages and session beans, you can reference the managed Todo bean using this name. If no instance of this class exists when it is referenced from another component, then Seam will instantiate one.

The @Id annotation defines a primary key id field for the component. @GeneratedValue specifies that the server will automatically generate this value for the component when it is saved to the database.

Seam provides support for model-based constraints defined using Hibernate Validator, although Hibernate does not have to be the object persister used. The @NotNull annotation is a validation constraint that requires this property to have a value before the component can be persisted into the database. Using this annotation allows the validation to be enforced by the JSF code at the view level, without having to specify the exact validation constraint in the JSF code.

At this point the only apparent difference between the Seam version and the EJB3/JSF version of the app is the inclusion of the validator annotation @NotNull, and the @Name annotation. However, while the EJB3/JSF version of this application requires a further TodoBean class to be manually coded and managed in order to handle the interaction between the Todo class and the web interface, when using Seam the Seam framework takes care of this work for us. We'll see how this is done in practice as we examine the implementation of the user interface.

The index.xhtml file used is the same as in the EJB3/JSF example.

create.xhtml begins to reveal the difference that coding using the Seam framework makes.

<h:form id="create">

<f:facet name="beforeInvalidField">
  <h:graphicImage styleClass="errorImg" value="error.png"/>
<f:facet name="afterInvalidField">
  <s:message styleClass="errorMsg" />
<f:facet name="aroundInvalidField">
  <s:div styleClass="error"/>



        <h:inputText id="title" value="#{todo.title}" size="15"/>

        <h:inputTextarea id="description" value="#{todo.description}"/>



<h:commandButton type="submit" id="create" value="Create"

The first thing that is different here is the Java Server Facelet code at the beginning, which works with the @NotNull validation constraint of our todo class to enforce and indicate invalid input to the user.

Also notice here that rather than requiring the use of a TodoBean class as we did in the EJB3/JSF example we back the form directly with a Todo entity bean. When this page is called, JSF asks Seam to resolve the variable todo due to JSF EL references such as #{todo.title}. Since there is no value already bound to that variable name, Seam will instantiate an entity bean of the todo class and return it to JSF, after storing it in the Seam context. The Seam context replaces the need for an intermediary bean.

The form input values are validated against the Hibernate Validator constraints specified in the todo class. JSF will redisplay the page if the constraints are violated, or it will bind the form input values to the Todo entity bean.

Entity beans shouldn't do database access or transaction management, so we can't use the Todo entity bean as a JSF action listener. Instead, creation of a new todo item in the database is accomplished by calling the persist method of a TodoDao session bean. When JSF requests Seam to resolve the variable todoDao through the JSF EL expression #{todoDao.persist}, Seam will either instantiate an object if one does not already exist, or else pass the existing stateful todoDao object from the Seam context. Seam will intercept the persist method call and inject the todo entity from the session context.

Let's have a look at the TodoDao class (defined in TodoDao.java) to see how this injection capability is implemented.

Let's go through a listing of the code for the TodoDao class.

public class TodoDao implements TodoDaoInt {

  @In (required=false) @Out (required=false)
  private Todo todo;

  @PersistenceContext (type=EXTENDED)
  private EntityManager em;

  // Injected from pages.xml
  Long id;
  public String persist () {
    em.persist (todo);
    return "persisted";

  private List <Todo> todos;

  public void findTodos () {
    todos = em.createQuery("select t from Todo t")

  public void setId (Long id) {
    this.id = id;
    if (id != null) {
      todo = (Todo) em.find(Todo.class, id);
    } else {
      todo = new Todo ();
  public Long getId () {
    return id;

  public String delete () {
    em.remove( todo );
    return "removed";

  public String update () {
    return "updated";

  @Remove @Destroy
  public void destroy() {}


First of all notice that this is a stateful session bean. Seam can use both stateful and stateless session beans, the two most common types of EJB3 beans.

The @In and @Out annotations define an attribute that is injected by Seam. The attribute is injected to this object or from this object to another via a Seam context variable named todo, a reference to the Seam registered name of our Todo class defined in Todo.java.

The @PersistenceContext annotation injects the EJB3 Entity manager, allowing this object to persist objects to the database. Because this is a stateful session bean and the PersistenceContext type is set to EXTENDED, the same Entity Manager instance is used until the Remove method of the session bean is called. The database to be used (a persistence-unit) is defined in the file resources/META-INF/persistence.xml

Note that this session bean has simultaneous access to context associated with web request (the form values of the todo object), and state held in transactional resources (the EntityManager). This is a break from traditional J2EE architectures, but Seam does not force you to work this way. You can use more traditional forms of application layering if you wish.

The @DataModel annotation initializes the todos property, which will be outjected or "exposed" to the view. The @Factory annotated method performs the work of generating the todos list, and is called by Seam if it attempts to access the exposed DataModel property and finds it to be null. Notice the absence of property access methods for the todos property. Seam takes care of this for you automatically.

Let's take a look at the JSF code that we use for displaying and editing the list of todos, to get an idea of how to use these interfaces in practice.

Using the DataModel exposed property of the Session Bean it becomes trivial to produce a list of todos:


<h:dataTable value="#{todos}" var="todo">
    <f:facet name="header">Title</f:facet>
    <f:facet name="header">Description</f:facet>
    <a href="edit.seam?tid=#{todo.id}">Edit</a>

  <h:commandButton action="create"
            value="Create New Todo" type="submit"/>


When the JSF variable resolver encounters {#todos} and requests todos, Seam finds that there is no "todos" component in the current scope, so it calls the @Factory("todos") method to make one. The todos object is then outjected once the factory method is done since it is annotated with the @DataModel annotation.

Constructing the view for the edit page is similarly straight forward:

<h:form id="edit">
<f:facet name="beforeInvalidField">
  <h:graphicImage styleClass="errorImg" value="error.png"/>
<f:facet name="afterInvalidField">
  <s:message styleClass="errorMsg" />
<f:facet name="aroundInvalidField">
  <s:div styleClass="error"/>



        <h:inputText id="title" value="#{todo.title}" size="15"/>

        <h:inputTextarea id="description" value="#{todo.description}"/>



<h:commandButton type="submit" id="update" value="Update"
<h:commandButton type="submit" id="delete" value="Delete"

Here we see the same factors in play. JSF validation code taking advantage of the validation constraints defined in our Entity Bean, and the use of the todoDao Session Bean's update and delete methods to update the database.

The call from todos.xhtml: edit.seam?tid=#{todo.id} causes Seam to create a todoDao and set it's id property to tid. Setting its id property causes the todoDao to retrieve the appropriate record from the database.

The functionality that allows the edit page to be called with a parameter in this way is implemented through pages.xml. Let's have a look at the pages.xml file and how it is used by Seam applications.

In the previous chapters, we’ve been using the JBossAS default datasource in our applications. This datasource is configured to use the embedded Hypersonic database instance shipped by default with the distribution. This datasource is bound to the JNDI name java:/DefaultDS and its descriptor is named hsqldb-ds.xml under the deploy directory

Having a database included with JBossAS is very convenient for running the server and examples out-of-the-box. However, this database is not a production quality database and as such should not be used with enterprise-class deployments. As a consequence of this JBoss Support does not provide any official support for Hypersonic.

In this chapter we will explain in details how to configure and deploy a datasource to connect JBossAS to the most popular database servers available on the market today.

Datasource configuration file names end with the suffix -ds.xml so that they will be recognized correctly by the JCA deployer. The docs/example/jca directory contains sample files for a wide selection of databases and it is a good idea to use one of these as a starting point. For a full description of the configuration format, the best place to look is the DTD file docs/dtd/jboss-ds_1_5.dtd. Additional documentation on the files and the JBoss JCA implementation can also be found in the JBoss Application Server Guide available at http://labs.jboss.com/projects/docs/.

Local transaction datasources are configured using the local-tx-datasource element and XA-compliant ones using xa-tx-datasource. The example file generic-ds.xml shows how to use both types and also some of the other elements that are available for things like connection pool configuration. Examples of both local and XA configurations are available for Oracle, DB2 and Informix.

If you look at the example files firebird-ds.xml, facets-ds.xml and sap3-ds.xml, you’ll notice that they have a completely different format, with the root element being connection-factories rather than datasources. These use an alternative, more generic JCA configuration syntax used with a pre-packaged JCA resource adapter. The syntax is not specific to datasource configuration and is used, for example, in the jms-ds.xml file to configure the JMS resource adapter.

We would also highly recommend consulting the JCA wiki pages at http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossJCA

Next, we’ll work through some step-by-step examples to illustrate what’s involved setting up a datasource for a specific database.

The MySQL® database has become the world's most popular open source database thanks to its consistent fast performance, high reliability and ease of use. This database server is used in millions of installations ranging from large corporations to specialized embedded applications across every continent of the world. . In this section, we'll be using the community version of their database server (GA 5.0.45) and the latest JDBC driver (GA 5.1.5) both available at http://www.mysql.com.

Oracle is one of the main players in the commercial database field and most readers will probably have come across it at some point. You can download it freely for non-commercial purposes from http://www.oracle.com/technology/products/database/xe/index.html

In this section, we'll connect the server to Oracle Database 10g Express Edition using the latest JDBC driver (11g) available at http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html

In this section, we'll connect the server to MS SQL Server 2000 using the latest JDBC driver (v1.2) available at http://msdn2.microsoft.com/en-us/data/aa937724.aspx.

Developers wanting to get familiar with software development and implementation in JBoss Application Server can read: JBoss: A Developer's Notebook . (O'Reilly, 2005. Norman Richards, Sam Griffith).

For more comprehensive JBoss documentation covering advanced JBoss topics, refer to the manuals available online at http://www.jboss.org/jbossas/docs.

For general EJB instruction, with thorough JBoss coverage, see Enterprise JavaBeans, 4th Edition . (O'Reilly, 2004. Richard Monson-Haeful, Bill Burke, Sacha Labourey)

To learn more about Hibernate, see Java Persistence With Hibernate . (Manning, 2007. Christian Bauer, Gavin King)

For complete coverage of the JBoss Seam framework, we recommend JBoss Seam: Simplicity And Power Beyond Java EE . (Prentice Hall, 2007. Michael Yuan, Thomas Heute).