JAVA 2 SOFTWARE PREPARATION AND INSTALLATION

This document has been prepared for all who are interested in using Java 2, Java Server Pages, Servlets, and all other Server Side Java programming. This document is intended to give simple instructions for the installation and the use of Java2 in both Client Side and Server Side programming.


_____________________________________________________________________________

1. Preparation of Your System for Java Software Installation

Choose a drive and directory name for your Java2 software installation. For the purposes of this document, drive d: has been chosen to hold the Java software. the directory d:\j2sesdk has been chosen as the install directory. Clearly, the drive d: and the directory name may be whatever you wish.

Create a directory, d:\j2sesdk with the command (at a Command Prompt) of

c:> mkdir d:\j2sesdk

You will use this directory to hold the Java2 software and all of the files that are listed below. Subdirectories under this directory will be created by the installation software.

You must now define a number of system enviornment variables. You do this in Control Panel by clicking (from your desktop):

Start>Settings>ControlPanel>System>Advanced>EnviornmentVariables

You must create two (system) enviornment variables:

JAVA_HOME=d:\j2sesdk CLASSPATH=.;d:\j2sesdk\lib\tools.jar; d:\j2sesdk\servlet.jar; d:\j2sesdk\jspengine.jar; d:\j2sesdk\xml.jar; (all on one line)

Also, you must add to the PATH enviornment variable:

d:\j2sesdk\bin

To perform the above mentioned task, you must have Administrator privledges. After you have done this, you must logout and log back in for the changes to take effect.

_____________________________________________________________________________

2. Installation of the Java2 Software

On the companion CD-ROM, you will find generator program to install the Java 2 (1.3.1) Standard Edition (SE) Software Development Kit (SDK). This programs is a self extracting archive file for use in the Windows NT 4.0 and Windows 2000 enviornments, which means that the installation of the software is accomplished by execution of the generator program at an MS-DOS Command Prompt.

The files included on the CD-ROM are as follows:

J2SESDK.EXE (34.5M) A self-extracting archive file containing the Java 2 (1.3) Standard Edition Software Development Kit.

J2SEDOC.ZIP (22.3M) A compressed (WinZip) file containing the Documentation for the Standard Edition SDK. Program WinZip.exe will decompress, expand, etc., all of the directories and files.

JSWDK101.ZIP (.77M) A compressed (WinZip) file containing the server software for Servlets and JSP.

To install the software, proceed as follows:

A. Mount the companion CD-ROM in your CD-ROM drive and do what is necessary to make it ready. Let us assume that your CD is drive e:. Then, type the following lines at a command prompt: d: cd \j2sesdk e:j2sesdk.exe When the installation prompts you, enter d:\j2sesdk for the install directory.

B. Use WinZip.exe to decompress the file e:\j2sedoc.zip into directory d:\j2sesdk. This puts the documentation into the directory d:\jesesdk\jdk1.3

C. Use WinZip.exe to decompress the file e:\jswdk101.zip into directory d:\j2sesdk. This puts the Servlet and JSP server software into directory d:\j2sesdk\jswdk-1.0.1 .

For your later convenience, type the following at a command prompt: d: cd \j2sesdk rename jdk1.3 jdk13 rename jswdk-1.0.1 jswdk101 copy d:\j2sesdk\jswdk101\lib\*.jar d:\j2sesdk The above is to be done for those of us with beautiful directory browser programs written shortly after the French and Indian War. This makes your software follow the 8+3 naming convention, and keeps the enviornment variables reasonably short.

Your software should now be installed. Client side software programming is now possible. For Server side programming, you must start a servlet server, which is described below.

_____________________________________________________________________________

3. Validation of Installation and Proper Operation of the Java Software

To check the installation, create a file called hello.java, thus:

class hello{ public static void main (String args[]) { System.out.println(" Hello World ! "); } }

Compile this program by typing:

javac hello.java

Run this program by typing:

java hello

This should produce the message, " Hello World ! ". If you do not see this, you have done something wrong; stop right here and do something until things are repaired.

_____________________________________________________________________________

4. Validation of Proper Operation of Java Applets

Create a file, hello.htm, thus:

`HTML> `HEAD> `TITLE>scios `BODY> `P>"This is a test routine!" `APPLET Code="helloworld.class" Width="200" Height="150"> `/applet> `/BODY> `/HTML>

Also, create a file, helloworld.java, thus:

import java.awt.Graphics; public class helloworld extends java.applet.Applet { public void init() { resize(600,300); } public void paint(Graphics context) { context.drawString("Hello World!",50,60); } }

Compile helloworld.java by typing:

javac helloworld.java

Using either Internet Explorer 5.0 and/or Netscape 4.7, enter for the URL:

d:\j2eesdk\hello.htm

A window should be presented to validate the proper operation of the applet.

Copy the files hello.class, hello.htm, and helloworld.class to the directory that is the "home" for your web server. On a computer which has been given the computer name "vaio", which is running IIS under Windows 2000, the "home" directory is usually:

c:\inetpub\wwwroot

This copying is accomplished by typing (at a command prompt):

copy hello*.* c:\inetpub\wwwroot

To bring up hello.htm with Internet Explorer 5.0 or Netscape 4.7, you type:

http://vaio/hello.htm

into the textbox for the URL. The applet helloworld.java will be executed.

_____________________________________________________________________________

5. Validation of Proper Operation of the Java Servlets

Let us also assume that your computer name is "vaio". Let us also assume that IIS is up and running and the servlet engine has been started by typing the following: d: cd \j2sesdk\jswdk101 startserver.bat

Create a file, hellowww.java, thus:

import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class hellowww extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException { PrintWriter out = response.getWriter(); out.println(" Hello WWW"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException { doGet(request, response); } }

Compile this program by typing:

javac hellowww.java

Create a file hellowww.htm, thus:

`html> `head> `title>HTML Driver to Call Servlets '/title> `meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> `/head> `body bgcolor="#FFFFFF"> `p> `font face="Arial, Helvetica, sans-serif"> `b> `font size="+2"> Servlet Example `/font> `/b> `br> `/p> `center> `a href="../servlet/hellowww"> Execute hellowww `/a> `/center> `/body> `/html>

Please follow the instructions in the next two paragraphs. You have been warned. Follow these instructions to the letter! :

Copy any html (.htm or .html) files and any JSP (.jsp) files i.e., files that employs JSP or Servlet capiabilities, to the directory: d:\j2sesdk\jswdk101\examples\servlets !

Copy any java class (.class) files which are servlets to the directory: d:\j2sesdk\jswdk101\examples\WEB-INF\servlets !

Please notice that in the .htm file above, that "servlet" is used. In the directory names, "servlets" is used. Let's hear it for the clear thinking on the part of the designers.

To execute the servlet hellowww.java directly from Internet Explorer 5.0 or Netscape 4.7, you type:

http://vaio:8080/examples/servlets/hellowww

in the textbox for the URL. The servlet hellowww.java will be executed.

To bring up hellowww.htm from Internet Explorer 5.0 or Netscape 4.7, you type:

http://vaio:8080/examples/servlets/hellowww.htm

in the textbox for the URL. The servlet hellowww.java will be executed when you click in the appropriate place on the screen that is presented.

The standard installation employs directory "examples" and it uses port 8080 rather than the usual 80 for the http server. The purists may want to change these default parameters by editing the file d:\j2sesdk\jswdk101\webserver.xml. However, watch out for collisions with other web servers that may be using port 80 without your knowledge.

Welcome to Java 2, Java Server Pages and Servlets.