17
Installing JDK and Tomcat Vijayan Sugumaran Department of DIS Oakland University

JDK Tomcat

Embed Size (px)

Citation preview

Page 1: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 1/17

Installing JDK and Tomcat

Vijayan Sugumaran

Department of DISOakland University

Page 2: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 2/17

Downloading JDK

JDK 6 (J2SE v1.6.0_03) installer can be downloadedfrom the following url:http://java.sun.com/javase/downloads/index.jsp

Click on the Download button

Click on Accept (license agreement) and continue

Click on the link for online installation: Windows Online Installation, Multi-language

Run the installer 

 Accept all the default settings. It will create a newdirectory (C:\Program Files\Java\jdk1.6.0_03) and therewill be a subdirectory called ³bin´ which contains all the

 jdk tools (javac, java, etc.). There will also be another subdirectory called ³lib´ that contains the .jar files

Page 3: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 3/17

Setting Environment Variables

In order to access the java binary filesfrom any directory, we should set thePATH environment variable

To access .class files from other locations, we need to set theCLASSPATH variable.

The CLASSPATH variable can alsoindicate where to look for .jar files

Page 4: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 4/17

Setting Path and Classpath

Right mouse click on ³My Computer´ and select the³Properties´ option

The system properties panel will pop up. Click on the³Advanced´ tab.

Click on the ³Environment Variables´ button If the Path and Classpath variables are already

defined, then you can add values at the end byclicking on the ³Edit´ button.

The directories are separated by semicolon

If the variables don¶t exist, then you can create themby clicking on the ³New´ button, and enter the valuesfor those variables (see next slide)

The first value for the classpath variable should be³.;´ that indicates current directory

Page 5: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 5/17

System Properties Panel

Page 6: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 6/17

Downloading and Installing

Tomcat

Download url:

http://tomcat.apache.org/download-60.cgi

Scroll down to the Binary Distributionssection and click on the zip link under 

Core to download tomcat 6.0.14.

The downloaded zip file needs to beunzipped. You can put the contents under 

Program Files or anywhere else you like.

Page 7: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 7/17

Configuring Tomcat

Make sure the ³JAVA_HOME´ environmentvariable exists. If not, create this variable andset it to C:\Program Files\Java\jdk1.6.0_03 (or the directory where jdk resides)

For now, leave the port to 8080 (you canchange it to another port number later in theserver.xml file)

Turn on Servlet Reloading Open the context.xml file (C:\Program Files \apache-tomcat-

6.0.14 \conf  \context.xml) using notepad

In the context.xml file, change <Context> to (it iscase sensitive) <Context reloadable="true privileged=true>

Page 8: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 8/17

Configuring Tomcat (Contd) Enable the Invoker Servlet

Uncomment the servlet and servlet-mapping elements in the web.xml file (C:\ProgramFiles \apache-tomcat-6.0.14 \conf  \web.xml)

<!-- (remove this line)

<servlet>

<servlet-name>invoker</servlet-name>

<servlet-class> org.apache.catalina.servlets.InvokerServlet

</servlet-class>

<init-param>

<param-name>debug</param-name>

<param-value>0</param-value>

</init-param>

<load-on-startup>2</load-on-startup>

</servlet> --> (remove this line)

<!-- (remove this line)

<servlet-mapping>

<servlet-name>invoker</servlet-name>

<url-pattern>/servlet/*</url-pattern>

</servlet-mapping>

--> (remove this line)

Page 9: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 9/17

Configuring Tomcat (contd)

Turn on Directory Listings when there isno welcome-file (optional)

Edit the conf/web.xml file as follows

<servlet><servlet-name>default</servlet-name>

<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>

<init-param>

<param-name>debug</param-name>

<param-value>0</param-value>

</init-param><init-param>

<param-name>listings</param-name>

<param-value>true</param-value>

</init-param>

<load-on-startup>1</load-on-startup>

</servlet>

Page 10: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 10/17

Test the Server 

Start the server 

Click on C:\Program Files\apache-tomcat-

6.0.214/bin/startup.bat

Open a browser window and type the url:

http://localhost:8080/

The Tomcat page should show up

Try some simple HTML and JSP Pages

Try executing the servlet examples Need to set up a development environment

so that you can compile your own servlets.

They need to be in a specific locaiton.

Page 11: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 11/17

Directory Structure of Web Application

Page 12: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 12/17

Setting up the Application

Directory Structure

Create a directory for each application withinthe webapps (C:\Program Files\apache-tomcat-6.0.14\webapps) directory and thenecessary sub directories within it.

Example: Create a directory called ³HelloApp´ for the ³hello

world´ application within the webapps directory

Within HelloApp, create a subdirectory called

³WEB-INF´ Within WEB-INF, create a subdirectory called

³classes´

The compiled servlets have to reside in the³classes´ directory

Page 13: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 13/17

Creating, Compiling & Executing a Servlet

Type the code for the Hello servlet usingnotepad

Save it as Hello.java in the following directory:C:\Program Files \apache-tomcat-6.0.14 \webapps \HelloApp \WEB-INF \classes

 Add the path for the servlet-api.jar and jsp-api.jar files to the classpath variable (C:\Program Files \apache-tomcat-6.0.14 \lib \servlet-api.jar;

C:\Program Files \apache-tomcat-6.0.14 \lib \ jsp-api.jar; )

Compile the Hello.java file using javac

The Hello.class file will be created and it shouldalso reside in the same classes directory

Executing the Hello servlethttp://localhost:8080/HelloApp/servlet/Hello

Page 14: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 14/17

Creating a New Web Application

Steps to create a new web applicationcalled ³anotherapp´

Create the appropriate directory structure

Restart Tomcat

 Add one or more servlets to the application

Test the servlets

To control the behavior of this application

add web.xml file to the WEB-INF directory If a web.xml file is not provided for this

application, the install_dir/conf/web.xml filewill be used

Page 15: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 15/17

Creating the Directory Structure

(Review)

Create a folder called ³anotherapp´ (or any other name you choose) within theinstall_dir/webapps folder 

Create the ³WEB-INF´ folder within the³myapps´ folder 

Create the ³classes´ folder within the

³WEB-INF´ folder  For now, make sure that you don¶t have

web.xml file within the WEB-INFdirectory

Page 16: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 16/17

Remaining Steps

Restart Tomcat

 Add one or more servlets to the ³anotherapp´application

Create the servlet source file (.java file) in theinstall_dir/webapps/anotherapp/WEB-INF/classesdirectory

Compile the source file using javac

 Alternatively, you can put the source file(s)anywhere you want, compile them, and then movethe .class files into theinstall_dir/webapps/anotherapp/WEB-INF/classesdirectory

Test the servlet (say you created Hello.class) http://localhost:8080/anotherapp/servlet/Hello

Page 17: JDK Tomcat

8/7/2019 JDK Tomcat

http://slidepdf.com/reader/full/jdk-tomcat 17/17

Deployment Descriptor File ±

WEB-INF/web.xml The install_dir/conf/web.xml file controls thebehavior of all the web applications that areunder the webapps directory

If you want a particular web application tobehave differently, then you add the web.xmlfile within the WEB-INF directory

It is not absolutely necessary that you should

have the web.xml file for the application  Among other things, the web.xml file may

contain the values of parameters that wouldbe used during servlet initialization (callingthe init() method)