Getting Started

JBoss Enterprise Application Platform

Red Hat Documentation Group

Copyright © 2008 Red Hat, Inc. This material may only be distributed subject to the terms and conditions set forth in the Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License (which is presently available at http://creativecommons.org/licenses/by-nc-sa/3.0/).

Red Hat and the Red Hat "Shadow Man" logo are registered trademarks of Red Hat, Inc. in the United States and other countries.

All other trademarks referenced herein are the property of their respective owners.

The GPG fingerprint of the security@redhat.com key is:

CA 20 86 86 2B D6 9D FC 65 F6 EC C4 21 91 80 CD DB 42 A6 0E

1801 Varsity Drive
RaleighNC 27606-2072
USA
Phone: +1 919 754 3700
Phone: 888 733 4281
Fax: +1 919 754 3701
PO Box 13588
Research Triangle ParkNC 27709
USA

Sep, 2007

Abstract

This book provides post-installation information about JBoss Enterprise Application Platform. Use this guide to familiarise yourself with the platform and the sample applications that demonstrate application development and deployment.


About this book
1. Introduction
1.1. Feedback
1.2. Other Manuals
2. The JBoss Server - A Quick Tour
2.1. Directory Structure
2.1.1. JBoss Top Level Directory Structure
2.1.2. JBOSS_DIST/jboss-as Directory Structure
2.2. Server Configurations
2.2.1. Server Configuration Directory Structure
2.2.2. The "default" Server Configuration File Set
2.2.3. The "all" Server Configuration File Set
2.2.4. EJB3 Services
2.2.5. Adding Your Own Configuration
2.3. Starting and Stopping the Server
2.3.1. Start the Server
2.3.2. Start the Server With Alternate Configuration
2.3.3. Using run.sh
2.3.4. Stopping the Server
2.3.5. Running as a Service under Microsoft Windows
2.4. The JMX Console
2.5. Hot-deployment of services in JBoss
2.6. Basic Configuration Issues
2.6.1. Core Services
2.6.2. Logging Service
2.6.3. Security Service
2.6.4. Additional Services
2.7. The Web Container - Tomcat
3. EJB3 Caveats in JBoss Enterprise Application Platform 4.2
3.1. Unimplemented features
3.2. Referencing EJB3 Session Beans from non-EJB3 Beans
4. About the Example Applications
4.1. Install Ant
5. Sample JSF-EJB3 Application
5.1. Data Model
5.2. JSF Web Pages
5.3. EJB3 Session Beans
5.4. Configuration and Packaging
5.4.1. Building The Application
5.4.2. Configuration Files
5.5. The Database
5.5.1. Creating the Database Schema
5.5.2. The HSQL Database Manager Tool
5.6. Deploying the Application
6. Using Seam
6.1. Data Model
6.2. JSF Web Pages - index.xhtml and create.xhtml
6.3. Data Access using a Session Bean
6.4. JSF Web Pages - todos.xhtml and edit.xhtml
6.5. Building The Application
6.6. Xml Files
6.7. Further Information
7. Using other Databases
7.1. DataSource Configuration Files
7.2. Using MySQL as the Default DataSource
7.2.1. Creating a Database and User
7.2.2. Installing the JDBC Driver and Deploying the DataSource
7.2.3. Testing the MySQL DataSource
7.3. Setting up an XADataSource with Oracle 9i
7.3.1. Padding Xid Values for Oracle Compatibility
7.3.2. Installing the JDBC Driver and Deploying the DataSource
7.3.3. Testing the Oracle DataSource
A. Further Information Sources

About this book

The goal of this book is to give you an overview of JBoss Enterprise Application Platform, and demonstrate some of its features and capability to provide a rapid application development and deployment environment for Enterprise Java Applications. At the time of writing, the latest release is version 4.2. You should use this version or later with the example applications. The example applications described in this book illustrate the development and deployment of Enterprise Java applications in JBoss Enterprise Application Platform. While the book is not intended to teach you Enterprise Java development, we will be covering the subject from quite a basic standpoint, so it will still be useful if you are new to Enterprise Java Application Development.

We will provide you a quick tour of the JBoss Directory Structure, basic Server Configuration, key configuration files and the JMX and Web Consoles. As we move on to the example applications, you will see JBoss Enterprise Application Platform in action and get some exposure in simple configuration and deployment issues. We will introduce the Seam framework and demonstrate the significant difference that Seam makes to application development.

Of course, that barely scratches the surface of what you can do with JBoss Enterprise Application Platform. Once you feel comfortable with the information here, the JBoss Enterprise Application Platform: Server Configuration Guide can take you through the rest of the way to total mastery of JBoss Enterprise Application Platform.

Chapter 1. Introduction

JBoss Enterprise Application Platform is easy to install and you can have it running in a few easy steps. Refer to the JBoss Enterprise Application Platform: Installation Guide for information on pre-requisites for installation and the detailed installation steps.

Once you have JBoss Enterprise Application Platform installed, use this guide to familiarize yourself with its layout and the example applications that demonstrate application development and deployment.

1.1. Feedback

If you spot a typo in this guide, or if you have thought of a way to make this manual better, we would love to hear from you! Submit a report in JIRA against the Product: JBoss Enterprise Application Platform, Version: <version>, Component: Doc. If you have a suggestion for improving the documentation, try to be as specific as possible. If you have found an error, include the section number and some of the surrounding text so we can find it easily.

1.2. Other Manuals

If you are looking for detailed product information refer to the manuals available online at http://www.redhat.com/docs/manuals/jboss.

Chapter 2. The JBoss Server - A Quick Tour

Let's explore the JBoss Enterprise Application Platform directory structure and help you understand how the installation is laid out and what goes where. It’s worth familiarizing yourself with the layout, locations of the key configuration files, log files, deployment and so on. 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.

2.1. Directory Structure

2.1.1. JBoss Top Level Directory Structure

Installing JBoss Enterprise Application Platform creates a top level directory, which will be named jboss-eap-<version> if you used the zip installation method, and will be named according to your specification if you used the GUI installer. Throughout this guide we refer to this top-level directory as the JBOSS_DIST directory. There are four sub-directories immediately below this:

  • doc: contains the product documentation.

  • jboss-as: contains sub directories that contain server start scripts, JARs, server configuration sets and working directories. You need to know your way around the distribution layout to locate JARs for compiling code, updating configurations, deploying your code, etc.

  • seam: contains the files for Hibernate and the JBoss Seam Framework.

  • Uninstaller: contains the uninstaller program uninstaller.jar.

Below is the layout of the installation directory of JBoss Enterprise Application Platform. In the figure, the default server configuration file set is shown expanded. In a clean installation, within the server/default directory only the conf, deploy, and lib directories exist. The data, log, tmp and work sub-directories are created by JBoss and won’t exist until you’ve run the server at least once. Section 2.3, “Starting and Stopping the Server” will teach you to run the server.

jboss-eap-<version>                  // jboss.home_url
	|+ doc
	|+ jboss-as
		|+ bin
		|+ client
		|+ docs
		|+ icons
		|+ lib                         // jboss.lib.url
		|+ scripts
		|+ server
			|+ all                // jboss.server.name
			|+ default            // jboss.server.home.url
				|+ conf       // jboss.server.config.url
				|+ deploy
				|+ lib        // jboss.server.lib.url
				|+ data
				|+ log
				|+ tmp
				|+ work
			|+ minimal
			|+ production
	|+ seam
	|+ Uninstaller                      // jboss.uninstaller.url

Several of the locations may be overridden. For these locations, the org.jboss.system.server.ServerConfig interface constant and its corresponding system property string are shown in the figure. The names ending in URL correspond to locations that can be specified using a URL to access remote locations, for example, HTTP URLs against a web server.

2.1.2. JBOSS_DIST/jboss-as Directory Structure

The table below illustrates the contents of the jboss-as directory.

Directory Description
bin Contains startup, shutdown and other system-specific scripts. Basically all the entry point JARs and start scripts included with the JBoss distribution are located in the bin directory.
client Stores configuration files and JAR files that may be used by a Java client application (running outside JBoss) or an external web container. You can select archives as required or use jbossall-client.jar.
docs Contains the XML DTDs used in JBoss for reference (these are also a useful source of documentation on JBoss configuration specifics). There are also example JCA (Java Connector Architecture) configuration files for setting up datasources for different databases (such as MySQL, Oracle, Postgres).
lib Contains startup JARs used by JBoss. Do not place your own JAR files in this directory.
server Contains the JBoss server configuration sets. Each of the subdirectories in here is a different server configuration. JBoss ships with minimal, default, production, and all configuration sets. The subdirectories and key configuration files contained in the default configuration set are discussed in more detail in subsequent sections.
Table 2.1. Contents of JBOSS_DIST/jboss-as directory


2.2. Server Configurations

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 don’t need to do this to be able to run standard J2EE applications though. Everything you need is already there.

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 Enterprise Application Platform ships with four different server configurations. Within the JBOSS_DIST/jboss-as/server directory, you will find four subdirectories: minimal, default, production and all - one for each server configuration. Each of these configurations provide a different set of services. The production configuration is the one used if you don’t specify another one when starting up the server.

minimal

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 J2EE technologies. This is just the bare server. There is no web container, no EJB or JMS support. This is not a J2EE 1.4 compatible configuration.

default

is a base J2EE 1.4 server profile containing a default set of services. It has the most frequently used services required to deploy a J2EE application. It does not include the JAXR service, the IIOP service, or any of the clustering services. Please note that although this configuration is called "default", the actual default configuration for the server is the "production" configuration.

all

on the other hand has all the services configured to launch every single component. This is a full J2EE 1.4 server profile with enterprise extensions such as Clustering and RMI/IIOP.

production

is based on the "all" profile, tuned for production; with log verbosity reduced, deployment scanning every 60 seconds, and memory usage tuned to accomodate production deployment requirements, among other things. This is the configuration that will be used by the server when it is started, if no other configuration is specified.

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

[vsr]$ls server/default/conf 
jbossjta-properties.xml  jndi.properties   standardjbosscmp-jdbc.xml
jboss-log4j.xml          login-config.xml  standardjboss.xml
jboss-minimal.xml        props             xmdesc
jboss-service.xml        standardjaws.xml

Note

The production configuration is the one used if you don’t specify another one when starting up the server.

To start the server using an alternate configuration refer to Section 2.3.2, “Start the Server With Alternate Configuration”.

2.2.1. Server Configuration Directory Structure

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 2.2, “Server Configuration Directory Structure” shows the directories inside the server configuration directory (JBOSS_DIST/jboss-as/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. This may be overridden through the URLDeploymentScanner URLs attribute.
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/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 2.2. Server Configuration Directory Structure


2.2.2. The "default" Server Configuration File Set

The "default" server configuration file set is located in the JBOSS_DIST/jboss-as/server/default directory. Let's take a look at the contents of the default server configuration file set:

jboss-eap-<version>                // jboss.home_url
	|+ doc
	|+ jboss-as
		|+ bin
		|+ client
		|+ docs
		|+ icons
		|+ lib                        // jboss.lib.url
		|+ scripts
		|+ server
			|+ all               // jboss.server.name
			|+ default           // jboss.server.home.url
				|+ conf      // jboss.server.config.url
					|+ props
					|+ xmdesc
					-  jbossjta-properties.xml  
					-  jboss-minimal.xml  
					-  jndi.properties                   
					-  standardjboss.xml
					-  jboss-log4j.xml
					-  jboss-service.xml
					-  login-config.xml
					-  standardjbosscmp-jdbc.xml
				|+ deploy
					|+ ejb3.deployer
					|+ http-invoker.sar
					|+ jboss-aop-jdk50.deployer
					|+ jboss-bean.deployer
					|+ jboss-web.deployer
					|+ jbossws.sar
					|+ jms
					|+ jmx-console.war
					|+ management
					|+ uuid-key-generator.sar
					-  bsh-deployer.xml
					-  cache-invalidation-service.xml
					-  client-deployer-service.xml
					-  ear-deployer.xml
					-  ejb3-interceptors-aop.xml
					-  ejb-deployer.xml
					-  hsqldb-ds.xml
					-  jboss-ha-local-jdbc.rar
					-  jboss-ha-xa-jdbc.rar
					-  jbossjca-service.xml
					-  jboss-local-jdbc.rar
					-  jboss-xa-jdbc.rar
					-  jmx-invoker-service.xml
					-  jsr88-service.xml
					-  mail-service.xml
					-  monitoring-service.xml
					-  properties-service.xml
					-  quartz-ra.rar
					-  schedule-manager-service.xml
					-  scheduler-service.xml
					-  sqlexception-service.xml
				|+ lib            // jboss.server.lib.url
			|+ minimal
			|+ production
	|+ seam
	|+ Uninstaller                          // jboss.uninstaller.url

2.2.2.1. Contents of "conf" directory

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

File Description
jboss-minimal.xml This is a minimalist example of the jboss-service.xml configuration file. (This is the jboss-service.xml file used in the minimal configuration file set)
jboss-service.xml jboss-service.xml defines the core services and their configurations.
jndi.properties The jndi.properties file specifies the JNDI InitialContext properties that are used within the JBoss server when an InitialContext is created using the no-arg constructor.
jboss-log4j.xml This file configures the Apache log4j framework category priorities and appenders used by the JBoss server code.
login-config.xml This file contains sample server side authentication configurations that are applicable when using JAAS based security.
props/* The props directory contains the users and roles property files for the jmx-console.
standardjaws.xml This file provides the default configuration for the legacy EJB 1.1 CMP engine.
standardjboss.xml This file provides the default container configurations.
standardjbosscmp-jdbc.xml This file provides a default configuration file for the JBoss CMP engine.
xmdesc/*-mbean.xml The xmdesc directory contains XMBean descriptors for several services configured in the jboss-service.xml file.
Table 2.3. Contents of "conf" directory


2.2.2.2. Contents of "deploy" directory

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 J2EE 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 J2EE EAR files.
ejb-deployer.xml The EJB deployer is the service responsible for deploying J2EE 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 J2EE web services support.
jms/hsqldb-jdbc-state-service.xml hsqldb-jdbc-state-service.xml provides JMS state management using Hypersonic.
jms/hsqldb-jdbc2-service.xml hsqldb-jdbc2-service.xml configures JMS persistence and caching using Hypersonic. It also contains the DestinationManager MBean, which is the core service for the JMS implementation.
jms/jbossmq-destinations-service.xml jbossmq-destinations-service.xml configures a number of JMS queues and topics used by the JMS unit tests.
jms/jbossmq-httpil.sar jbossmq-httpil.sar provides a JMS invocation layer that allows the use of JMS over HTTP.
jms/jbossmq-service.xml The jbossmq-service.xml file configures the core JBossMQ JMS service.
jms/jms-ds.xml The jms-ds.xml file configures the JBossMQ JMS provider for use with the jms-ra.rar JCA resource adaptor.
jms/jms-ra.rar jms-ra.rar is a JCA resource adaptor that implements the JCA ManagedConnectionFactory interface for JMS connection factories.
jms/jvm-il-service.xml jvm-il-service.xml configures the in-JVM JMS transport invocation layer.
jms/uil2-service.xml uil2-service.xml configures the JMS version 2 unified invocation layer. Its a fast and reliable custom socket based transport that should be used for messaging between JVMs.
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 2.4. Contents of "deploy" directory


2.2.3. The "all" Server Configuration File Set

The "all" server configuration file set is located in the JBOSS_DIST/jboss-as/server/all directory. In addition to the services in the "default" set, the all configuration contains several other services in the conf/ directory as shown below.

File Description
cluster-service.xml This service configures clustering communication for most clustered services in JBoss.
deploy-hasingleton-service.xml This provides the HA singleton service, allowing JBoss to manage services that must be active on only one node of a cluster.
deploy.last/farm-service.xml farm-service.xml provides the farm service, which allows for cluster-wide deployment and undeployment of services.
httpha-invoker.sar This service provides HTTP tunneling support for clustered environments.
iiop-service.xml This provides IIOP invocation support.
juddi-service.sar This service provides UDDI lookup services.
snmp-adaptor.sar This is a JMX to SNMP adaptor. It allows for the mapping of JMX notifications onto SNMP traps.
tc5-cluster.sar Provides AOP support for field-level HTTP session replication.
Table 2.5. Additional Services in "conf" directory for "all" configuration


2.2.4. EJB3 Services

The following table explains the files providing ejb3 services.

File Description
ejb3-interceptors-aop.xml This service provides the AOP interceptor stack configurations for EJB3 bean types.
ejb3.deployer This service deploys EJB3 applications into JBoss.
jboss-aop-jdk50.deployer This is a Java 5 version of the AOP deployer. The AOP deployer configures the AspectManagerService and deploys JBoss AOP applications.
jbossws.sar This provides Java EE 5 web services support.
Table 2.6. EJB3 Services


Finally, in the EJB3 "all" configuration there are two additional services.

File Description
ejb3-clustered-sfsbcache-service.xml This provides replication and failover for EJB3 stateful session beans.
ejb3-entity-cache-service.xml This provides a clustered cache for EJB3 entity beans.
Table 2.7. Additional Services in EJB3 "all" Configuration


2.2.5. Adding Your Own Configuration

You can add your own configurations too. The best way to do this is to copy an existing one that is closest to your needs and modify the contents. For example, if you weren’t interested in using messaging, you could copy the production directory, renaming it as myconfig, remove the jms subdirectory and then start JBoss with the new configuration.

run -c myconfig

2.3. Starting and Stopping the Server

2.3.1. Start the Server

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. Your output should look like the following (accounting for installation directory differences) and contain no error or exception messages:

[jwulf@thinkpad bin]$ ./run.sh 
=========================================================================

  JBoss Bootstrap Environment

  JBOSS_HOME: /home/jwulf/jboss-eap-4.2/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/jwulf/jboss-eap-4.2/jboss-as/bin/run.jar

=========================================================================

13:11:46,215 INFO  [Server] Starting JBoss (MX MicroKernel)...
.
.
.
.
13:11:47,071 INFO  [ServerInfo] Java version: 1.5.0_11,Sun Microsystems Inc.
13:11:47,071 INFO  [ServerInfo] Java VM: 
Java HotSpot(TM) Server VM 1.5.0_11-b03,Sun Microsystems Inc.
13:11:47,072 INFO  [ServerInfo] OS-System: Linux 2.6.21-1.3228.rhel5,i386
13:11:48,558 INFO  [Server] Core system initialized
13:11:56,934 INFO  [WebService] Using RMI server codebase: http://127.0.0.1:8083/
13:11:56,940 INFO  [Log4jService$URLWatchTimerTask] 
Configuring from URL: resource:jboss-log4j.xml

Note

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.

2.3.2. Start the Server With Alternate Configuration

Using run.sh without any arguments starts the server using the production server configuration file set. To start with an alternate configuration file set, pass the name of the server configuration file set [same as the name of the server configuration directory under JBOSS_DIST/jboss-as/server] that you want to use, as the value to the -c command line option. For example, to start with the minimal configuration file set you should specify:

[bin]$ ./run.sh -c minimal
...
...
...
15:05:40,301 INFO  [Server] JBoss (MX MicroKernel) [4.2.0.GA (build: SVNTag=JBoss_4_2_0_GA date=200706111042)] Started in 5s:75ms

2.3.3. Using run.sh

The run script supports the following options:

usage: run.sh [options]
-h, --help                          Show help message
-V, --version                       Show version information
--                                  Stop processing options
-D<name>[=<value>]      Set a system property
-d, --bootdir=<dir>           Set the boot patch directory; Must be absolute or url
-p, --patchdir=<dir>          Set the patch directory; Must be absolute or url
-n, --netboot=<url>           Boot from net with the given url as base
-c, --configuration=<name>    Set the server configuration name
-B, --bootlib=<filename>      Add an extra library to the front bootclasspath
-L, --library=<filename>      Add an extra library to the loaders classpath
-C, --classpath=<url>         Add an extra url to the loaders classpath
-P, --properties=<url>        Load system properties from the given url
-b, --host=<host or ip>       Bind address for all JBoss services
-g, --partition=<name>        HA Partition name (default=DefaultDomain)
-u, --udp=<ip>                UDP multicast address
-l, --log=<log4j|jdk>         Specify the logger plugin type

2.3.4. Stopping the Server

To shutdown the server, you simply issue a Ctrl-C sequence in the console in which JBoss was started. Alternatively, you can use the shutdown.sh command.

[bin]$ ./shutdown.sh -S

The shutdown script supports the following options:

A JMX client to shutdown (exit or halt) a remote JBoss server.

usage: shutdown [options] <operation>

options:
-h, --help                Show this help message (default)
-D<name>[=<value>]        Set a system property
--                        Stop processing options
-s, --server=<url>        Specify the JNDI URL of the remote server
-n, --serverName=<url>    Specify the JMX name of the ServerImpl
-a, --adapter=<name>      Specify JNDI name of the MBeanServerConnection to use
-u, --user=<name>         Specify the username for authentication
-p, --password=<name>     Specify the password for authentication

operations:
-S, --shutdown            Shutdown the server
-e, --exit=<code>         Force the VM to exit with a status code
-H, --halt=<code>         Force the VM to halt with a status code

Using the shutdown command requires a server configuration that contains the jmx-invoker-service.xml service. Hence you cannot use the shutdown command with the minimal configuration.

2.3.5.  Running as a Service under Microsoft Windows

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:

JBossInstall.bat <depends> [-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.

2.4. The JMX Console

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 2.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.

View of the JMX Management Console Web Application
Figure 2.1. View of the JMX Management Console Web Application

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.

Note

If you installed JBoss using the graphical installer, the JMX Console will prompt you for a username and password before you can access it. If you installed using other modes, you can still configure JMX Security manually. We will show you how to secure your console in Section 2.6.3, “Security Service”.

2.5. Hot-deployment of services in JBoss

Hot-deployable services are those which can be added to or removed from the running server. These are placed in the JBOSS_DIST/jboss-as/server/<instance-name>/deploy directory. Let’s have a look at a practical example of hot-deployment of services in JBoss before we go on to look at server configuration issues in more detail.

Start JBoss if it isn’t already running and take a look at the server/production/deploy directory. Remove the mail-service.xml file and watch the output from the server:

13:10:05,235 INFO  [MailService] Mail service 'java:/Mail' removed from JNDI

Then replace the file and watch JBoss re-install the service:

13:58:54,331 INFO  [MailService] Mail Service bound to java:/Mail

This is hot-deployment in action.

2.6. Basic Configuration Issues

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).

2.6.1. Core Services

The core services specified in the conf/jboss-service.xml file are started first when the server starts up. If you have a look at this file in an editor you will see MBeans for various services including logging, security, JNDI, JNDIView etc. Try commenting out the entry for the JNDIView service.

Note that because the mbeans definition had nested comments, we had to comment out the mbean in two sections, leaving the original comment as it was.

<!-- Section 1 commented out
<mbean code="org.jboss.naming.JNDIView"
    name="jboss:service=JNDIView"
    xmbean-dd="resource:xmdesc/JNDIView-xmbean.xml">
-->
    <!-- The HANamingService service name -->
<!-- Section two commented out
    <attribute name="HANamingService">jboss:service=HAJNDI</attribute></mbean>
-->

If you then restart JBoss, you will see that the JNDIView service no longer appears in the JMX Management Console (JMX Console) listing. In practice, you should rarely, if ever, need to modify this file, though there is nothing to stop you adding extra MBean entries in here if you want to. The alternative is to use a separate file in the deploy directory, which allows your service to be hot deployable.

2.6.2. Logging Service

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/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 (server.log in the log directory).

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="INFO"/> 
</category>

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 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"/> 
    </layout> 
</appender> 
 
<category name="org.jboss.ejb.plugins.cmp"> 
    <priority value="DEBUG" /> 
    <appender-ref ref="CMP"/> 
</category>

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 the name. You will notice that the log directory also contains HTTP request logs which are produced by the web container.

2.6.3. Security Service

The security domain information is stored in the file login-config.xml as a list of named security domains, each of which specifies a number of JAAS [1] 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 and/or jboss-web.xml. We will quickly look at how to do this to secure the JMX Console application.

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. [2] 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.

<jboss-web>
    <security-domain>java:/jaas/jmx-console</security-domain>
</jboss-web>

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.
-->
<security-constraint>
    <web-resource-collection>
        <web-resource-name>HtmlAdaptor</web-resource-name>
        <description>
            An example security config that only allows users with the
            role JBossAdmin to access the HTML JMX console web application
        </description>
        <url-pattern>/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>JBossAdmin</role-name>
    </auth-constraint>
</security-constraint>

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">
    <authentication>
        <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
                     flag="required">
            <module-option name="usersProperties">
                props/jmx-console-users.properties
            </module-option>
            <module-option name="rolesProperties">
                props/jmx-console-roles.properties
            </module-option>
        </login-module>
    </authentication> 
</application-policy>

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. 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. [3]

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/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.

2.6.4. Additional Services

The non-core, hot-deployable services are added to the deploy directory. They can be either XML descriptor files, *-service.xml, or JBoss Service Archive (SAR) files. SARs contain both the XML descriptor and additional resources the service requires (e.g. classes, library JAR files or other archives), all packaged up into a single archive.

Detailed information on all these services can be found in the JBoss Enterprise Application Platform: Server Configuration Guide, which also provides comprehensive information on server internals and the implementation of services such as JTA and the J2EE Connector Architecture (JCA).

2.7. The Web Container - Tomcat

JBoss Enterprise Application Platform comes with Tomcat as the default web container. The embedded Tomcat service is found in the deploy/jboss-web.deployer directory. All the necessary jar files needed by Tomcat can be found in there, as well as a web.xml file which provides a default configuration set for web applications.

If you are already familiar with configuring Tomcat, have a look at the server.xml, which contains a subset of the standard Tomcat format configuration information. As it stands, this includes setting up the HTTP connector on the default port 8080, an AJP connector on port 8009 (can be used if you want to connect via a web server such as Apache) and an example of how to configure an SSL connector (commented out by default).

You shouldn’t need to modify any of this other than for advanced use. If you’ve used Tomcat before as a stand-alone server you should be aware that things are a bit different when using the embedded service. JBoss is in charge and you shouldn’t need to access the Tomcat directory at all. Web applications are deployed by putting them in the JBoss deploy directory and logging output from Tomcat can be found in the JBoss log directory.



[1] 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.

[2] If you installed JBoss using the Graphical Installer and set the JMX Security up, then you will not have to uncomment the sections, because they are already uncommented. Additionally, the admin password will be set up to whatever you had specified.

[3] Since the username and password are session variables in the web browser you may need to shut down your browser and come back in to see the login dialog come back up.

Chapter 3.  EJB3 Caveats in JBoss Enterprise Application Platform 4.2

There are a number of implementation features that you should be aware of when developing applications for JBoss Enterprise Application Platform 4.2.

3.1.  Unimplemented features

The Release Notes for JBoss Enterprise Application Platform 4.2 contain information on EJB3 features that are not yet implemented, or partially implemented. The Release Notes include links to issues in JIRA for information on workarounds and further details.

3.2.  Referencing EJB3 Session Beans from non-EJB3 Beans

JBoss Enterprise Application Platform 5 will fully support the entire Java 5 Enterprise Edition specification. In the meantime JBoss Enterprise Application Platform 4.2 implements EJB3 functionality by way of an EJB MBean container running as a plugin in the JBoss Application Server. This has certain implications for application development.

The EJB3 plugin injects references to an EntityManager and @EJB references from one EJB object to another. However this support is limited to the EJB3 MBean and the JAR files it manages. Any JAR files which are loaded from a WAR (such as Servlets, JSF backing beans, and so forth) do not undergo this processing. The Java 5 Enterprise Edition standard specifies that a Servlet can reference a Session Bean through an @EJB annotated reference, however this is not implemented in JBoss Enterprise Application Platform 4.2.

In order to access an EJB3 Session Bean from a Servlet or JSF Backing Bean you will need to do one of two things:

  1. Without Seam - JNDI Lookup

    Without utilizing the Seam framework that is part of JBoss Enterprise Application Platform 4.2 you will need to use an explicit JNDI lookup to access the EJB3 Session Bean. You can see an example of this being done in the TodoBean.java file in the jsfejb3 example application, described in Chapter 5, Sample JSF-EJB3 Application.

    private TodoDaoInt getDao () {
    	try {
    	InitialContext ctx = new InitialContext();
    	return (TodoDaoInt) ctx.lookup("jsfejb3/TodoDao/local");
    	} catch (Exception e) {
    	e.printStackTrace();
    	throw new RuntimeException("couldn't lookup Dao", e);
    	}
    	}
    

    ctx.lookup("jsfejb3/TodoDao/local"); is the method used to reference the EJB3 Session Bean. The form is: AppName/SessionBeanName/local.

  2. With Seam - Leave it to the Seam Framework

    When you are using the Seam Framework you don't need to worry about this. Because the Seam framework manages the interaction of Beans anyway, it already automates this type of interaction.

    Refer to Chapter 6, Using Seam for a more detailed explanation of achieving this using the Seam framework.

Chapter 4. About the Example Applications

In this guide, we make use of a simple web application to illustrate 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/gettingstarted 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/gettingstarted/jsfejb3 directory. 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 working of the .java, .xml and .properties files.

The second example used in this guide can be found in the JBOSS_DIST/doc/examples/gettingstarted/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/gettingstarted/<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.

4.1. Install Ant

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
    

Chapter 5. Sample JSF-EJB3 Application

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.

5.1. Data Model

Let's take a look at the contents of the Data Model represented by the Todo class in the Todo.java file. Each instance of the Todo class corresponds to a row in the relational database table. The 'Todo' class has three properties: id, title and description. Each of these correspond to a column in the database table.

The 'Entity class' to 'Database Table' mapping information is specified using EJB3 Annotations in the 'Todo' class. This eliminates the need for XML configuration and makes it a lot clearer. The @Entity annotation defines the Todo class as an Entity Bean. The @Id and @GeneratedValue annotations on the id property indicate that the id column is the primary key and that the server automatically generates its value for each Todo object saved into the database.

@Entity
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;
  }

}

5.2. JSF Web Pages

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:

  • index.xhtml: This page displays two options: 1. Create New Todo 2. Show all Todos. When you click on the Submit button the corresponding action is invoked.

    <h:form>
    <ul>
      <li><h:commandLink type="submit" value="Create New Todo" action="create"/></li>
      <li><h:commandLink type="submit" value="Show All Todos" action="todos"/></li>
    </ul>
    </h:form>
    

  • create.xhtml: When you try to create a new task, this JSF page captures the input data. We use the todoBean to back the form input text fields. The #{todoBean.todo.title} symbol refers to the "title" property of the "todo" object in the "TodoBean" class. The #{todoBean.todo.description} symbol refers to the "description" property of the "todo" object in the "TodoBean" class. The #{todoBean.persist} symbol refers to the "persist" method in the "TodoBean" class. This method creates the "Todo" instance with the input data (title and description) and persists the data.

    <h:form id="create">
    <table>
      <tr>
        <td>Title:</td>
        <td>
          <h:inputText id="title" value="#{todoBean.todo.title}" size="15">
            <f:validateLength minimum="2"/>
          </h:inputText>
        </td>
      </tr>
      <tr>
        <td>Description:</td>
        <td>
          <h:inputTextarea id="description" value="#{todoBean.todo.description}">
            <f:validateLength minimum="2" maximum="250"/>
          </h:inputTextarea>
        </td>
      </tr>
    </table>
    <h:commandButton type="submit" id="create" value="Create"
                     action="#{todoBean.persist}"/>
    </h:form>
    

    Figure 5.1, “The "Create Todo" web page ” shows the "Create Todo" web page with the input fields mapped to the data model.

    The "Create Todo" web page
    Figure 5.1. The "Create Todo" web page

  • todos.xhtml: This