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

Plugins: The heart of Eclipse


The most important architectural characteristics of Eclipse is the plugin architecture. A plugin in Eclipse is a component that provides a certain type of service within the context of the Eclipse workbench. The Eclipse IDE itself is built with a number of plugins, which are dependent on each other, so that you can customize your development environment exactly for your needs.

Installing JBoss Tools plugins

JBoss plugins for Eclipse are part of the JBoss suite. You can find them in the JBoss Tools project, which is an umbrella project for all the JBoss developer plugins. JBoss Tools plugins can be downloaded from:

http://www.jboss.org/tools

The installation of the JBoss tools can be performed in two ways—one is directly from your Eclipse IDE, the other choice (covered in the next section) is the manual installation of single plugin files.

So, once you have started Eclipse, move onto the last menu option Help, and select Install New Software (former releases of Eclipse name this menu option Software Updates). In the upper combo box, you need to select the repository for your Eclipse plugins. JBoss Tools is not installed by default, so you need to add a link to JBoss Tools trunk. The list of available update sites can be found at http://www.jboss.org/tools/download.

Once there, select the release that matches with your Eclipse distribution. For example, if you have downloaded the Eclipse 3.5 (Galileo) release, there's a development update available at http://download.jboss.org/jbosstools/updates/development/.

Tip

For learning, it is appropriate to use a development update. However, consider sticking to a stable release of JBoss Tools for your cutting-edge software projects.

Once added, expand the JBoss Tools update site and you'll see the list of available plugins. For the purpose of this book, all you need is the JBoss AS plugin, the Hibernate plugin, and JBoss Tools RichFaces plugin.

Check them and click on the Next button, which will confirm your selections. Finish and wait for the time necessary to download the tools. Once the download is completed you will be prompted to restart Eclipse.

Installing JBoss Tools plugins manually

You can mimic the behavior of the Update Manager by installing the JBoss Tools plugins manually into your Eclipse installation.

The list of JBoss Tools plugins is available at http://www.jboss.org/tools/download.

Download the single JBoss AS plugin and Hibernate plugin zip files.

The structure of the single plugin's archive resembles the same structure of your Eclipse installation:

eclipse/
    features/
    plugins/

Once the download completes, you simply need to extract the plugins into the Eclipse installation directory.

For example, if you are using the command line and your Eclipse installation directory is named eclipse, navigate to the directory above your Eclipse installation and extract the archive using the unzip command.

 unzip JBossTools-2.1.2.GA-ALL-linux-gtk.zip

Tip

Automatic versus manual installation

Automatic installation is the easiest solution because the wizard takes care to place all the necessary files in the right place, so we recommend it for developers who are approaching Eclipse with JBoss. However, manual setup is the preferred choice if you have to perform lots of installations for your developers because you can easily create a script that simply extracts the required files on multiple partitions. Manual installation is also the preferred choice when you need to change the plugin versions because switching from one release to another merely requires a file substitution.

If you are not too confident with shell commands, you might consider a third alternative of downloading the .zip files containing the plugins, and pointing to the archive from the Software Updates menu as New Local Site.

Connecting Eclipse with JBoss

We're almost done with the configuration. The last piece of the puzzle is connecting Eclipse with our installation of JBoss. Eclipse enterprise provides some out of the box facets to manage most application servers. However, we'll use the features of JBoss Perspective , which offers a richer set of options.

Tip

What is an Eclipse perspective?

A perspective is a visual container for a set of views and editors. These components are specific to that perspective and are not shared with other perspectives. You can think about it like a page within a photo book.

Therefore, the JBoss Perspective is a special view designed specifically for JBoss AS.

You can reach it from the menu. Select Window, then Open Perspective and Other. Select JBoss AS from the next menu.

Now a tiny little panel will appear in left-corner section of the screen. This panel holds the JBoss Server View. Right-click on it and select New | Server.

You'll be guided by an intuitive wizard that will at first ask you to select the Server's host name, the JBoss Community AS release, and the Runtime Environment.

Tip

Deploy-only servers

Notice that among the available servers there's a Deploy-Only option that will simply point to the deploy directory. You can use this option if you don't need to start/stop/debug your AS, but simply deploy applications.

In the next window, you will have to complete your server configuration by adding a JBoss Runtime.

What is a Runtime Environment ? Put it simply, it is a pointer to the JBoss server installation. It provides to Eclipse all classpath information that is required for each kind of project. It also communicates to the server’s components, all the necessary information to start and stop the server.

Basically, we need to choose a Name for our environment, point to the Home Directory where JBoss AS has been unpacked, and finally select the location where JDK/JRE has been installed.

Tip

More is better

It is a good idea to create several runtime environments if you are going to test your project across different configurations. Remember to give a meaningful description to your runtime environment. For example, it's better to have a "JBoss Development" and "JBoss Production" rather than "JBoss Runtime 1" and "JBoss Runtime 2"

Once you have completed the selections, click Finish and your new runtime will be added to the list and can now be targeted by a JBoss server. Right-click on your new server icon and verify that the application server starts correctly.