Javaedge Setup and Installation
Total Page:16
File Type:pdf, Size:1020Kb
APPENDIX A ■ ■ ■ JavaEdge Setup and Installation Throughout the book, we have used the example application, JavaEdge, to provide a practical demonstration of all the features discussed. In this appendix, we will walk you through setting up the tools and applications required to build and run JavaEdge, as well as take you through the steps needed to get the JavaEdge application running on your platform. Environment Setup Before you can get started with the JavaEdge application, you need to configure your platform to be able to build and run JavaEdge. Specifically, you need to configure Apache Ant in order to build the JavaEdge application and package it up for deployment. In addition, the JavaEdge application is designed to run on a J2EE application server and to use MySQL as the back-end database. You also need to have a current JDK installed; the JavaEdge application relies on JVM version 1.5 or higher, so make sure your JDK is compatible. We haven’t included instruc- tions for this here, since we are certain that you will already have a JDK installed if you are reading this book. However, if you do need to download one, you can find it at http://java. sun.com/j2se/1.5.0/download.jsp. Installing MySQL The JavaEdge application uses MySQL as the data store for all user, story, and comment data. If you don’t already have the MySQL database server, then you need to obtain the version applicable to your platform. You can obtain the latest production binary release of MySQL for your platform at http://www.mysql.com. The code with this application has been tested with the 4.0 release of MySQL, however, it should work just fine with a later release. Windows Setup The Windows distribution of MySQL comes complete with a Windows Installer package that will automatically install and configure MySQL on your system. If you are running on Win- dows NT, 2000, or XP, you need administrative privileges in order to get the installation to succeed. 433 434 APPENDIX A ■ JAVAEDGE SETUP AND INSTALLATION Once you have downloaded the MySQL setup file, unzip it to a temporary directory and then run the setup.exe file. The setup program will take you through a series of steps that will allow you to choose which components are installed and where they are installed to. When choosing an installation directory, try to avoid any paths that contain spaces, as these have been known to cause problems. Once the installation is complete, the easiest way to start and manage the MySQL server is to use the WinMySQLAdmin tool. You will find this tool in the {mysql_home}\bin directory, and once you have run it for the first time, it will run each time the machine starts. WinMySQLAdmin puts a small icon in the taskbar, and by right-clicking this icon, you can easily start and stop the MySQL server. Linux RPM Setup The simplest way to install MySQL is to use the RPM packages supplied on the download site. If your system doesn’t support RPM packages, then read the instructions in the next section. If you choose to install from the RPM package, then you need to obtain two separate RPM files, one for the server and one for the client tools. The filenames for these packages are MySQL-server-VERSION.i386.rpm and MySQL-client-VERSION.i386.rpm, respectively, where VERSION is the version number of MySQL you are downloading. Once you have obtained the correct files, you can use the RPM package manager on your system to install MySQL. Many modern Linux distributions will allow you to do this graphi- cally, but if you prefer to use the shell or you have to use the shell, then you can install with this command: rpm -i MySQL-server-VERSION.i386.rpm MySQL-client-VERSION.i386.rpm This will install MySQL in the /var/lib/mysql directory and will also configure the system to start MySQL automatically at boot time with the appropriate entries in the /etc/init.d file. Now that the database server is installed, all that remains is to configure the basic mysql data- base and to test that the installation runs. To install the mysql database, you need to switch to the installation directory and run the following command: ./scripts/mysql_install_db Then you can start up the server in a background process using the mysql_safe tool: ./bin/mysql_safe –user=mysql & You can start mysql directly if you choose, but using the mysql_safe wrapper tool is the preferred mechanism. If the server won’t start or you experience any installation issues, then you should check out the MySQL web site at http://www.mysql.com. Linux Non-RPM Setup If you are running a Linux distribution that does not support RPM packages, you can install MySQL directly from a binary distribution. The binary distribution is packaged as a tar file. Installing the binary distribution directly involves performing many tasks such as configuring the group and user for MySQL and setting permissions that were performed automatically by the RPM installation. After downloading the tar file, you should issue the following commands at the shell prompt: APPENDIX A ■ JAVAEDGE SETUP AND INSTALLATION 435 shell> groupadd mysql shell> useradd -g mysql mysql shell> cd /usr/local shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf - shell> ln -s full-path-to-mysql-VERSION-OS mysql shell> cd mysql shell> scripts/mysql_install_db shell> chown -R root . shell> chown -R mysql data shell> chgrp -R mysql . shell> bin/mysqld_safe --user=mysql & This will configure a specific user and group for MySQL ownership and configure the appropriate permissions with the OS to enable MySQL to run. You will find a much more detailed explanation of this setup at http://www.mysql.com/documentation/mysql/bychapter/ manual_Installing.html#Installing_binary. Other OS Setup Windows and Linux are not the only operating systems that will run the MySQL database server. Most Unix-based operating systems such as Solaris, FreeBSD, and even Mac OS X will run MySQL. The MySQL web site has full installation instructions for all these operating systems. Changing the MySQL Root Password After installing the MySQL database server, the root password for the server is blank. You should change this as soon as you have started the server to prevent any security issues. By default, you can log in to the MySQL server as the root user by simply using this command: mysql –-user=root You will not be prompted for a password, so anyone could gain full access to your data- base. To rectify this, log on as a root user and issue the following commands to give the root user a password: use mysql; UPDATE user SET Password=PASSWORD('mypassword') WHERE user='root'; FLUSH PRIVILEGES; Log out of the server and try logging in again. You can’t. Now you need to use the follow- ing command to log in: mysql –user=root –p at which point MySQL will prompt you for the password you provided when modifying the user table in the mysql database. With that change made, you are all ready to go on the MySQL front. Now for JBoss. 436 APPENDIX A ■ JAVAEDGE SETUP AND INSTALLATION Installing JBoss With the database server ready and running, you now need to configure the application server on which to run the JavaEdge application. For this book, we have used the JBoss application server, and the JavaEdge application has been fully tested on JBoss. JBoss is a freely available open source package used by many developers worldwide. You can obtain the latest version, or any version above 3.2.2, from the JBoss web site at http://labs.jboss.com/portal/. Setting up JBoss is actually quite easy and requires very little effort. There are no OS-specific distributions of JBoss since it is all written in Java, but you can obtain the system in either a zip file or a tar file. Once you have downloaded the appropriate archive file, simply extract the files to a directory on the system. ■Caution Windows users: Avoid installing JBoss in a path that has spaces in the name and try to keep the path names as short as possible, because long path names may cause some problems with certain JDKs. Before running the JBoss application server, you should make sure that the JAVA_HOME environment variables point to the installation directory of your Java SDK; otherwise, JBoss will be unable to find the tools.jar file that it requires. Once you have set the JAVA_HOME environment variable, you can run the JBoss server. Windows users should run the run.bat file in the {jboss_home}\bin directory, whereas Unix and Mac OS X users should run the run.sh file in the same directory. ■Tip Unix users: Although Windows users will have to put up with the JBoss console window staying onscreen while the server is running, Unix users can run the JBoss start-up script as a background process using this command: {jboss_home}/bin/run.sh &. Once JBoss has started, you will see a message in the console indicating a successful start- up and how long it took. If this message does not appear, you will instead see the stack trace of the error. Visit the JBoss forums at http://www.jboss.com/index.html?module=bb to get some assistance with the problem. Installing Apache Ant The last tool you need to get up and running with the JavaEdge application is Apache Ant. As with JBoss, there is no platform-dependent distribution; you simply download either a zip or tar archive as you prefer.