Throughout the book, we evaded the topic of installing application servers and configuring our sample application inside an installed server. We avoided this subject for two reasons. First, this book is about the EJB 3 standard and we didn’t want to slant this book toward a specific application-server implementation. Second, providing application-server-specific instructions is a tricky business at best. This is because application-server implementations change quite often, making instructions out of date. This is especially true for a potentially long-lived technology like EJB 3.
However, we don’t want to leave you completely high and dry, even if it means providing instructions that may not be up-to-date when you read this. You should treat the material in this appendix as a general guideline more than anything else. We’ll provide the basic instructions for installing and configuring the ActionBazaar application using the Java EE SDK based on the GlassFish application server, which seems like an obvious choice since it’s the “official” reference implementation for Java EE 5. Note that in no sense do we endorse GlassFish as something you should be using for anything other than the purposes of learning EJB 3 with this book.
Also note that the website for this book, www.manning.com/panda, contains upto-date instructions for installing and configuring all popular application servers that support EJB 3. The instructions in this appendix are for a Windows machine, but they can be easily adapted for any other operating system, such as Linux.
The installation and configuration instructions can be broken down into three distinct steps:
Installing the Java EE 5 SDK
Configuring and running the application server and database
Installing and running the ActionBazaar application
Sun bundles a GlassFish distribution with the Java EE 5 SDK. The first logical step is to download and install the SDK from the Sun site.
You can download the Java EE 5 SDK from http://java.sun.com/javaee/technologies/index.jsp. You want the Java EE 5 SDK Update 2 (or the latest available for download). You can download the SDK with or without a JDK. Java EE 5 requires Java SE 5 or higher. The safest bet is to use the version that comes bundled with a JDK. This version of the downloaded file is named something like java_ee_sdk-5*-windows.exe.
Double-click on the downloaded executable and you will see the screen in figure E.1.
Click Next on this screen to start the installation process.
The next screen shows the licensing agreement (figure E.2). Click Yes to accept the agreement and click Next.
As shown in figure E.3, the next screen prompts you to enter an installation directory for the application server. Unless there is a specific reason not to do so, accept the default.
Figure E.3. The Select Installation Directory screen. Unless there is a reason not to do so, accept the defaults here.
The next screen (figure E.4) prompts you for some administrative details for the application server such as Admin User Name, Password, and the ports the server should use. Accept the default username, enter a password (twice), and accept the default port settings.
The next screen (figure E.5) prompts you with some installation options. You’ll need to change a few defaults here. You should deselect the Register Application Server option unless you really want to go through a few more tedious screens. Also, select the Create Windows Service option to make server startup happen behind the scenes.
The next screen displays an installation summary, as shown in figure E.6. Click Next to start the install process. The installation is not short, so you’ll have to wait a bit for it to finish. Feel free to go water the plants!
After the installation finishes, you’ll see the Installation Complete screen in figure E.7. Don’t be too quick to dismiss this screen. You must actually start the server by clicking the Start Server button on this screen. It will take a moment for the server to start. Once it does, you can close this screen by clicking the Finish button.
This completes the installation of the Java EE 5 SDK. The next major step is to configure GlassFish in preparation for deploying the ActionBazaar application.
At this point, you should verify that the application server is running. You can do this by accessing the built-in web-based administrative interface.
- The administrative interface runs on port 4848 of your local machine. To access it, go to Start > Programs > Sun Microsystems
> Application Server PE 9 > Admin Console. The first screen you see is the login interface (figure E.8). Enter the admin username and password you specified during installation here.
- The Server Admin Console home page shown in figure E.9 appears. Take a moment to explore the administration console before moving on.
- The Java EE 5 SDK comes with the default Apache Derby database. To simplify matters, you can use this database for the ActionBazaar
application. You must start the database to install and configure the sample code. To start the database, navigate to Start
> Programs > Sun Microsystems > Application Server PE 9 > Start Java DB, as shown in figure E.10.
- The Derby database will start in a command-line window. After the database starts, you’ll see a screen similar to the one
in figure E.11. By default, the Derby database is started in the background. You can safely close the command window by pressing the Enter
key at the prompt.
Now that both GlassFish and the Derby database are up and running, you are ready to install and run the ActionBazaar application.
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.
- The first step to installing the application is to download the source code bundle from http://manning.com/panda/. 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.
- 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.
- Open a command window. Type in the following:
This will prepare data sources and JMS resources necessary for the database. The output of the Ant task is shown in figure E.12.
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
If you’re using another database, such as Oracle XE, then you can configure the Java EE SDK (or reference implementation) server by typing
- You are now ready to start deploying the examples for each chapter. Each chapter example is packaged into a separate application.
To deploy an example application, move into the directory for the chapter and run the Ant task. For example, to deploy the
application for chapter 1, run
ant This Ant task will compile the classes, package them as an EJB-JAR/EAR, and then deploy the application into the GlassFish server.
- You can run the deployed application by typing
ant run 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.
Figure E.13. The output of running the deployed application for chapter 1
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.
Figure E.14. The deployed application for chapter 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.