Tomcat Setup BCIS 3680 Enterprise Programming

advertisement
Tomcat Setup
BCIS 3680 Enterprise Programming
Overview
Tomcat installation
Locating JDK
Getting Tomcat to run





Add new environment variables
Append new values to system PATH variable
Web application deployment



2
Alias and context
Deployment folder
Tomcat Installation
If you have included Tomcat when you installed NetBeans,
you have it already. Skip to Slide #7.
If you haven’t, download the Tomcat file from
http://tomcat.apache.org/download-70.cgi.
The latest version is 7.0.59. But previous versions, even
6.0, works just fine.



3
Tomcat Installation (Windows)
Unzip the downloaded file. The unzipping process may create
an additional layer of folder.
Locate the folder right above the Tomcat subfolders (bin, conf,
lib, etc.), i.e., apache-tomcat-7.0.56 for the current
version.


Do NOT
copy this
Copy this
4
Tomcat Installation (Windows)
Right-click the folder and select Copy or Cut.

5
Tomcat Installation (Windows)
Paste the folder to the root of a partition, e.g., C:\, D:\, etc.
It is highly recommended that you rename the folder to a short
name, e.g., D:\Tomcat.
Open the folder. Make sure you see the subfolders like \bin,
\conf, etc. immediately beneath it.



6
Locating JDK
Make sure you have JDK installed. If you have multiple
versions of JDK, uninstall all except the latest one.


It’s OK to keep JRE.
To find out where your JDK has been installed, select
Control Panel; then Programs and Features (Win7).

7
Locating JDK
Right click anywhere in the column heading row.
Select More… from the pop-up menu.


Right click
anywhere
in this row
8
Locating JDK
In the Choose Details
screen, select the
checkbox for “Location”
(it is not selected by
default).

9
Locating JDK


Scroll to the right until you see the “Location” column.
Click the “Location” heading and, while still pressing your
mouse button down, drag the heading to the left.
10
Locating JDK


When you can see both the application names and their
locations at the same time, release your mouse button.
You should be able to see your JDK installation folder.
11
Locating Tomcat


If you have installed Tomcat with NetBeans, you will be able to
locate its installation folder here as well.
If you unzipped Tomcat as shown earlier, you won’t see the
folder here.
12
Setting Up Tomcat on Your Computer

To start Tomcat, Windows needs to know where you
installed Tomcat and the JDK, as well as where to find the
executable files of Tomcat and Java.



These are done by adding/modifying system environment
variables.
To do this, right-click My Computer. Select
Properties. Click the Advanced tab. Then click the
Environment Variables button. Then click New
under System Variables.
Note on Vista or Win7 machines you’ll need admin right
to perform this task.
13
System Properties Screen
14
Add New Environment Variables

Click the “New” button in the System Variables pane
(bottom pane).
15
Add New Environment Variables
Type variable name
exactly as this (not
case sensitive)
Replace this with
your own Tomcat
installation path

Enter the variable name and its value. For Tomcat to work


Add JAVA_HOME – Value: Path to the JDK base folder (e.g.,
D:\Java\jdk1.6.0_16), not its bin subfolder.
Add CATALINA_HOME – Value: Path to the Tomcat base folder
(e.g., D:\Apache\Tomcat), not its bin subfolder.

16
Note in this and forthcoming screenshots,Tomcat was installed to D:\Apache\Tomcat. This is
different from previous screenshots showing Tomcat installation, when it was installed to
D:\Tomcat.
Verify System Variables

Start a command console by doing the following:





Click Start.
Click Run.
Type in cmd.
Click ‘OK”.
Alternatively, click Start | Accessories | Command
Prompt.
17
Checking CATALINA_HOME Variable


At the prompt, type set catalina_home and hit Enter.
If set correctly, you will see the name=value pair (in the
example below, the value of the variable has been set to
D:\Apache\Tomcat .
Note: The SET command ordinarily is used to set a new value for the variable from
inside the command console. But if we don’t provide a new value for the variable (as
in this example), the command returns the current value of the variable instead.
18
Checking JAVA_HOME Variable


At the prompt, type set java_home and hit Enter.
If set correctly, you will see the name=value pair (in the
example below, the value of the variable has been set to
D:\Java\jdk1.6.0_16.
19
Appending Values to PATH Variable

In the System Variables pane, find and select the Path
variable. Click the “Edit” button.
20
Appending Values to PATH Variable



Move mouse cursor all the way to the end of what’s in
the Path variable.
Add a semicolon, followed by the new value (path to a
folder).You don’t have to add a backslash to the end. In
this example, I am adding D:\Java\jkd1.6.0\bin.
Click “OK”.
21
Appending Values to PATH Variable

For Tomcat to work, it is necessary to append the
following two paths to the Path system variable:


22
Append to Path – The \bin subfolder of JDK (e.g.,
D:\Java\jdk1.6.0_16\bin)
Append to Path – The \bin subfolder of Tomcat (e.g.,
D:\Apache\Tomcat\bin)
Checking PATH Variable


At the prompt, type path and hit Enter.
Look for the paths to the binary folders for the JDK (in
this example, D:\Java\jdk1.6.0_16\bin) and
Tomcat (in this example, D:\Apache\Tomcat\bin).
23
Getting Web Apps to Work






Verify that Tomcat works.
Understand how context works.
Create folders/files for easy deployment of your web app.
Configure server.xml.
Configure web.xml.
Test your web app.
24
Verification of Tomcat


Start a command prompt and run command: catalina run
Tomcat is up if you see “INFO: Server startup in #### ms”
25
Exiting Tomcat




To exit Tomcat, get back to the command console.
Press CTRL + C simultaneously.
When asked whether to terminate batch job, type y and hit ENTER.
You often need to stop and restart Tomcat after making changes to
configurations or class files.
26
Alias for Web App




A web application consists of a collection of files that are
required to support a particular feature or task you want
to publish to the outside world. The set of files are
stored in a folder, which is the “deployment folder” for
the application. It can contain subfolders.
When provide visitors with the URL to your web app,
you don’t want to show them the physical path to the
deployment folder.
Instead, you create an “alias” (or “context” or “virtual
directory”) for the folder. In the URL, it is appended to
the domain name so that the URL points to that web app.
Append any file names and/or subfolder names to the
alias when accessing files directly under the deployment
folder or under one of its subfolders.
27
Folders for Deployment




On your USB drive, under the folder you created for
BCIS 3680, create a subfolder for each chapter/topic.
Download index.html and default.htm into the
deployment folder.
Inside the deployment folder, create a subfolder called
WEB-INF.
Download the web.xml file into this subfolder.
28
Modifying web.xml Under Win8/7/Vista
right click
29
Modifying web.xml Under Win7/Vista
30
Context for Web Applications



In Tomcat terminology, an alias is a “context”.
We want to set up a context for own our web app for
each topic.
Open the server.xml file in the \conf subfolder of
Tomcat installation folder. and modify it.



Unlike HTML, XML is case-sensitive!
Inside the “Host” element (tag), modify the “Context”
element. For example:
<Context path="/jsp" docBase="E:/BCIS
3680/jsp" debug="0" reloadable="true" />
Restart Tomcat.
31
Testing Web Site



After you have complete all the previous steps, you can
verify whether your web site is up and running by:
First, start Tomcat server from command prompt.
Second, open the browser and enter the following URL:
http://localhost:8080/<context>/default.htm
 Replace the <context> part with the alias you defined in the
server.xml file.
32
Testing localhost Site Under Win7/Vista
1
2
33
3
Download