2.1 Download and Install the Java Software Development Kit (SDK)
You probably have already installed the Java Platform, but if not, doing so should be your first step. Current versions of the servlet and JSP APIs require the Java 2 Platform (Standard EditionJ2SEor Enterprise EditionJ2EE). If you aren't using J2EE features like Enterprise JavaBeans (EJB) or Java Messaging Service (JMS), we recommend that you use the standard edition. Your server will supply the classes needed to add servlet and JSP support to Java 2 Standard Edition.
But what Java version do you need? Well, it depends on what servlet/JSP API you are using, and whether you are using a full J2EE-compliant application server (e.g., WebSphere, WebLogic, or JBoss) or a standalone servlet/JSP container (e.g., Tomcat, JRun, or Resin). If you are starting from scratch, we recommend that you use the latest Java version (1.4); doing so will give you the best performance and guarantee that you are compatible with future releases. But, if you want to know the minimum supported version, here is a quick summary.
We use Java 1.4 in our examples.
For Solaris, Windows, and Linux, obtain Java 1.4 at http://java.sun.com/j2se/1.4/ and 1.3 at http://java.sun.com/j2se/1.3/. Be sure to download the SDK (Software Development Kit), not just the JRE (Java Runtime Environment)the JRE is intended only for executing already compiled Java class files and lacks a compiler. For other platforms, check first whether a Java 2 implementation comes preinstalled as it does with MacOS X. If not, see Sun's list of third-party Java implementations at http://java.sun.com/cgi-bin/java-ports.cgi.
Your Java implementation should come with complete configuration instructions, but the key point is to set the PATH (not CLASSPATH !) environment variable to refer to the directory that contains java and javac , typically java_install_dir /bin . For example, if you are running Windows and installed the SDK in C:\j2sdk1.4.1_01 , you might put the following line in your C:\autoexec.bat file. Remember that the autoexec.bat file is executed only when the system is booted .
If you want to download an already configured autoexec.bat file that contains the PATH setting and the other settings discussed in this chapter, go to http://www.coreservlets.com/, go to the source code archive, and select Chapter 2.
On Windows NT/2000/XP, you could also right-click on My Computer, select Properties, then Advanced, then Environment Variables . Then, you would update the PATH value and press the OK button.
On Unix (Solaris, Linux, etc.), if the SDK is installed in /usr/j2sdk1.4.1_01 and you use the C shell, you would put the following into your . cshrc file.
setenv PATH /usr/j2sdk1.4.1_01/bin:$PATH
After rebooting (Windows; not necessary if you set the variables interactively) or logging out and back in (Unix), verify that the Java setup is correct by opening a DOS window (Windows) or shell (Unix) and typing java -version and javac -help . You should see a real result both times, not an error message about an unknown command. Alternatively, if you use an Integrated Development Environment (IDE) like Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, compile and run a simple program to confirm that the IDE knows where you installed Java.