Book Image

JBoss AS 5 Development

Book Image

JBoss AS 5 Development

Overview of this book

JBoss AS is the most used Java application server on the market meeting high standards of reliability, efficiency, and robustness and is used to build powerful and secure Java EE applications. It supports the most important areas of Java Enterprise programming including EJB 3.0, dependency injection, web services, the security framework, and more. Getting started with JBoss application server development can be challenging; however, with the right approach and guidance, you can easily master it and this book promises that. Written in an easy-to-read style, this book will take you from the basics of JBoss ASósuch as installing core components and plug-insóto the skills that will make you a JBoss developer to be reckoned with, covering advanced topics such as developing applications with JBoss Messaging service, JBoss web services, clustered applications, and more. You will learn the necessary steps to install a suitable environment for developing enterprise applications on JBoss AS. Then, your journey will continue through the heart of the application server, explaining how to customize each service for optimal usage. You will learn how to design Enterprise applications using Eclipse and JBoss plug-ins. You will then learn how to enable distributed communication using JMS. Storing and retrieving objects will be made easier using Hibernate. The core section of the book will take you into the programming arena with tested, real-world examples. The example programs have been carefully crafted to be easy to understand and useful as starting points for your applications. This book will kick-start your productivity and help you to master JBoss AS development. The author's experience with JBoss enables him to share insights on JBoss AS development, in a clear and friendly way. By the end of the book, you will have the confidence to apply all the newest programming techniques to your JBoss applications.
Table of Contents (20 chapters)
JBoss AS 5 Development
Credits
About the Author
About the Reviewers
Preface
8
Developing Applications with JBoss and Hibernate
Index

Installing JBoss AS 5


JBoss Application Server can be freely downloaded from the community site:

http://www.jboss.org/jbossas/downloads/.

Then, you'll soon be redirected to the SourceForge site where the project is hosted.

JBoss 5 is released in two different versions: jboss-5.0.0.GA.zip and jboss-5.0.0-jdk6.zip. The former version is the appropriate distribution if you are using JDK 1.5; the latter is the targeted release for JDK 1.6. Choose the appropriate distribution and start downloading.

Tip

At the time of writing, the newer stable release 5.1.0 of JBoss AS is available. The most important changes introduced by the new release include a new web administration console and the reactivation of the cluster farming option. For the purpose of running the examples of this book, you can safely use both the releases 5.0.0 and 5.1.0.

The installation of JBoss is simply a matter of extracting the compressed archive. Windows users can simply use any uncompressed utility, such as WinZip or WinRAR, taking care to choose a folder which doesn't contain empty spaces. Unix/Linux should use the unzip shell command to explode the archive:

$ unzip jboss5.0.0.GA-jdk6.zip

Tip

Security warning:

Unix/Linux users should be aware that JBoss AS does not require root privileges, as none of the default ports used by JBoss are below the 1024 privileged port range. To reduce the risk of users gaining root privileges through the JBoss AS, install and run JBoss as a non-root user.

Starting up JBoss AS

After you have installed JBoss, 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, move to the bin directory of your JBOSS_HOME directory. Once there, issue the following command:

run.bat    # Windows users
$ run.sh   # Linux/Unix users

Here's a sample JBoss AS 5 startup console:

The previous command starts up JBoss AS and binds the application server to the localhost network interface. This means JBoss cannot be accessed from another machine in your network. The first thing you should learn is how to bind JBoss to the IP address of your machine; this can be achieved with the -b option as follows:

run.bat -b 192.168.10.1     # Windows Users
run.sh -b 192.168.10.1      # Unix/linux Users

Here the server is bound to the IP address 192.168.10.1.

Tip

Using the IP address of the machine will also exclude the "localhost" network interface, which will no longer be accessible. If you want to bind your server to all available network interfaces, you can use –b 0.0.0.0.

You can verify that the server is reachable from the network by simply pointing the browser to http://192.168.10.1:8080.

Tip

Introducing the twiddle utility

One useful command-line utility that ships with JBoss is twiddle. This is a needful shell command located inside the JBOSS_HOME/bin folder. It can be used if you don't have a graphical terminal where you can manage JBoss, or if you want to control JBoss with shell scripts.

The syntax of twiddle is basically built into 3 pieces:

twiddle [options] <command> [command_arguments]

Here's an example command line for checking JBoss status:

twiddle -s 192.168.0.1 get "jboss.system:type=Server" Started

Stopping JBoss

Probably the easiest way to stop JBoss is sending an interrupt signal with the Ctrl + C key combination.

However, if your JBoss process was launched in the background or is running on another machine (see the next section), then you have to use the shutdown command from the bin folder:

shutdown -S         # Windows Users
./shutdown.sh -S    # Unix/Linux Users

Stopping JBoss on a remote machine

The shutdown script can also be used to shut down a remote JBoss server, contacting the JBoss naming provider on the remote host.

./shutdown.sh -s jnp://remoteHost:1099
Shutdown message has been posted to the server.
Server shutdown may take a while - check logfiles for completion

Tip

Unexpected shutdown?

Unix users sometimes reported unexpected shutdown of JBoss server.

For those who are not familiar with the Unix environment, when the terminal hangs up (drops the connection) the operating system sends a SIGHUP signal to all the programs that are launched from that terminal.

As Sun JVM monitors for SIGHUP signal, it can be interpreted as a signal to shut down. The workaround is to add the -Xrs option when launching JBoss. This is an option of the JVM, which reduces the use of operating system signals by the Java Virtual Machine.