Installing Java

Your choice of JVM can significantly affect the performance of your Tomcat server, and it’s worth evaluating a few to see which gives you the best performance. This is a subject that many people don’t concern themselves with or have never thought about, so you won’t be alone if you think that this isn’t an issue. Sun Microsystems’ JVM is all you need, right?

Well, if performance is really an issue and you want to squeeze as much out of your server setup as possible, you should look into this area. You can find a lot of information on the Internet, and Sun provides its own guidance at http://java.sun.com/docs/performance/.

IBM (http://www.ibm.com/developerworks/java/jdk/) and the Blackdown project (http://www.blackdown.org), which is a Linux port of source donated by Sun Microsystems, provide the main alternatives to Sun Microsystems’ Java development kit (JDK).

Installing Java on Windows

Download the Java installer from http://java.sun.com/j2se/downloads/. You can choose either JDK 1.4 or JDK 5.0, though the latter option isn’t a final release and you must use Tomcat 5.5.x.

The Java installer on Windows is a standard installation package with easy-to-follow steps. Start the installation by double-clicking the downloaded installer, and you’ll shortly have the JDK installed. Choose the folder where you want to install Java, which is referred to as %JAVA_HOME%. The %JAVA_HOME%\bin directory is where the installer places all the Java executables, including the JVM, the compiler, the debugger, and a packaging utility.

You’ll probably have noted that the installation directory was specified as if it were an environment variable. This is because you now have to add the installation folder as an environment variable called %JAVA_HOME% so that Windows can find the Java executables. Java itself doesn’t need this environment variable, but many third-party packages need to know where Java is, and Tomcat is no exception. Finally, add the %JAVA_HOME%\bin directory to the Windows path. This avoids clashes with other JVMs that may be on the system.

Setting Environment Variables

To set environment variables, select Start image from book Settings image from book Control Panel, and choose the System option. Now choose the Advanced tab, and click the Environment Variables button. You’ll see a screen like the one in Figure 2-1.

image from book
Figure 2-1: The Windows Environment Variables dialog box

The top window contains variables for the user you’re logged in as, which will be available only when you’re logged in as this user, and the bottom window contains system environment variables, which are available to all users. To add %JAVA_HOME% so that every user has access to it, click the New button below the bottom window; then enter JAVA_HOME as the variable name, and enter the directory where Java was installed as the value.

Next, modify the %Path% variable to include %JAVA_HOME%\bin, making sure it’s the first entry in the path to avoid any naming clashes. Adding this directory to the path will make the Java executables available at the command prompt. To test the installation, open an instance of the command prompt and type the following:

 > java -version 

You should then see version information as follows:

 java version "1.4.2_03"  Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)  Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode) 

In this example, JDK 1.4.2_03 is installed as the default Java. If you have the wrong version information, check that you’ve added the correct Java to the Windows path.

Setting Environment Variables in Windows 9x

In Windows 9x, you set the environment variables by editing the c:\autoexec.bat file. Open the file, and add the following path to your installation:

 set JAVA_HOME=c:\j2sdk1.4.2 

For Windows ME, you can use the System Configuration utility to set environment variables. To run it, choose Start image from book Programs image from book Accessories image from book System Tools image from book System Information. You’ll see a Microsoft help and support page, from which you should select the Tools menu and then the System Configuration utility. From here, select the Environment tab, and set the JAVA_HOME variable to point to your Java installation directory. Test the installation as mentioned previously.

Installing Java on Linux

Download a suitable distribution from http://java.sun.com/j2se/downloads/. Two types of download exist: a self-extracting binary file and an RPM package for systems supporting RPMs. You can choose either JDK 1.4 or JDK 5.0; the latter option isn’t a final release, and you must use Tomcat 5.5.x.

Installing Java Using the Self-Extracting Binary

Once you’ve obtained the self-extracting binary, you must set its execute permissions. Note that you don’t need to be a root user to install Java using the self-extracting binary, though you do need to be a root user if you want to install it in a system directory such as /usr/local; this is because the binary won’t overwrite any system files otherwise. To change the execute permissions, type the following command from the directory where the binary is located:

 # chmod +x j2sdk-1_4_2-linux-i586.bin 

Now change the directory to the one where you want to install Java and execute the binary. You must prefix the binary’s filename with any path information that’s necessary, like so:

 # ./j2sdk-1_4_2-linux-i586.bin 

This command will display a license agreement and, once you’ve agreed to the license, install Java in a j2sdk-1_4_2 directory in the current directory.

You need to add the $JAVA_HOME environment variable to your system to specify the location of the JDK. So, if you installed it in /usr/java/j2sdk-1_4_2_05-linux-i386, you should give $JAVA_HOME this value. To add it permanently, you can add it to your ~/.bashrc file or, if you want all users to have access to Java, to /etc/profile.

Alternatively, /etc/profile runs any shell scripts in /etc/profile.d, so you can add the following lines to a file named tomcat.sh:

 JAVA_HOME=/usr/java/j2sdk-1_4_2_05-linux-i386/  export JAVA_HOME  PATH=$JAVA_HOME/bin:$PATH  export PATH 

You may have to log out and log in again for your system to read /etc/profile or tomcat.sh. You should also add execute permissions for the $JAVA_HOME/bin folder for all the users who will be using Java as appropriate.

To test the installation, type the following:

 # java -version 

If the installation succeeded, you’ll see version information.

Installing Java Using the RPM Installer

To install the JDK using the RPM, you must first download the file. Unlike with the self-extracting binary, you must be a root user to install the RPM.

Sun Microsystems supplies the RPM as an executable to allow you to agree to the licensing terms. If you agree to the licensing terms, the RPM installer decompresses an RPM into the current directory. Before you can run the RPM, you have to set execute permissions for the file, like so:

 # chmod a+x j2sdk-1_4_2-linux-i586-rpm.bin  # ./j2sdk-1_4_2-linux-i586-rpm.bin  # rpm -iv jdk-1_4_2-linux-i586.rpm 

The RPM will install Java as a replacement of the Linux system version. You should now follow the previous instructions to add execute permissions for the JDK executables and modify the path to include them. Again, you can test the installation as described previously.



Pro Jakarta Tomcat 5
Pro Apache Tomcat 5/5.5 (Experts Voice in Java)
ISBN: 1590593316
EAN: 2147483647
Year: 2004
Pages: 94

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net