Installing and running ActionBazaar (EJB 3)

As you’ve seen, you can install and configure an application from the console. To make things a little easier on you, we are going to take a slightly simpler route. The ActionBazaar source code comes with Ant build scripts to deploy the application. If you are unfamiliar with Apache Ant, you may read up on it at http:// ant.apache.org. Ant is a way of automating common project configuration and deployment tasks that you would typically perform manually. Feel free to explore the XML Ant scripts we have supplied.

1 The first step to installing the application is to download the source code bundle from net The source file bundle is named codeexamples-javaeesdk.zip. Unzip the source into any directory, such as c:\ejb_3_in_action\code_examples.

We assume that you will be using the Derby database shipped with GlassFish, so the data sources in the Ant setup script are for Derby. However, you could use any other database, such as MySQL, PostgreSQL, or the free Oracle XE (www.oracle.com/technology/products/database/xe/index.html) database. You’ll simply need to make the appropriate changes to the Ant tasks.

If you plan to use a database other than Derby, don’t forget to copy the JDBC driver to the %RI_HOME%\lib directory and restart RI server. For example, if you want to use the Oracle XE database, then copy the ojdbc14.jar JDBC driver to the server library directory.


2 Edit the common.xml file in the code examples directory root and change the admin password for GlassFish. If you are using a database other than Derby, you’ll need to change the jdbc.url and other database information in the build.xml file in the code examples root.

3 Open a command window. Type in the following:

tmp4B-412

This will prepare data sources and JMS resources necessary for the database. The output of the Ant task is shown in figure E.12.

If you’re using another database, such as Oracle XE, then you can configure the Java EE SDK (or reference implementation) server by typing

tmp4B-413 The output from the command-line Ant task that sets up the data sources and JMS resources necessary for the ActionBazaar application

Figure E.12 The output from the command-line Ant task that sets up the data sources and JMS resources necessary for the ActionBazaar application

4 You are now ready to start deploying the examples for each topic. Each topic example is packaged into a separate application. To deploy an example application, move into the directory for the topic and run the Ant task. For example, to deploy the application for topic 1, run

tmp4B-415

This Ant task will compile the classes, package them as an EJB-JAR/EAR, and then deploy the application into the GlassFish server.

5 You can run the deployed application by typing

tmp4B-416

The output printed by the EJB will be printed to the log file of the application server. In our case, the contents of the C:\Sun\SDK\domains\ domain1\logs\server.log will have the entry shown in figure E.13.

A very interesting thing to consider is how the deployed application— including the data sources and the JMS resources—looks in the admin console. If you go back to the admin console, you’ll see something similar to figure E.14.

The output of running the deployed application for topic 1

Figure E.13 The output of running the deployed application for topic 1

The deployed application for topic 1 in the admin console

Figure E.14 The deployed application for topic 1 in the admin console

You can explore the code further by opening it up in an IDE. At the time of this writing, NetBeans and Oracle JDeveloper had good support for EJB 3 and Java EE 5 in general. However, it is very likely that other popular IDEs such as Eclipse will catch up very soon.

Next post:

Previous post: