Manual Tomcat
-
Upload
enkido654321 -
Category
Documents
-
view
255 -
download
0
Transcript of Manual Tomcat
-
8/12/2019 Manual Tomcat
1/60
Contenido
Contenido................................................................................................................................1Chapter 1. Revision History....................................................................................................3
Chapter 2. Introduction...........................................................................................................42.1. Why Am I Writing This ?............................................................................................4
2.2. Copyright !icense and "ther Caveats.........................................................................42.3. What is Tomcat ?.........................................................................................................4
2.4. Why #hou$d I %se It ?..................................................................................................&
2.&. Tomcat 'ersions..........................................................................................................&2.(. Tested )$at*orms...........................................................................................................(
Chapter 3. Insta$$ing Tomcat...................................................................................................+
3.1. )rere,uisites.................................................................................................................+3.2. -on$oading The #o*tare.........................................................................................+
3.3. Insta$$ing The #o*tare................................................................................................/
3.4. #tarting and #topping Tomcat......................................................................................03.&. Running Tomcat as onRoot %ser...........................................................................1
Chapter 4. -ep$oying We App$ications..............................................................................12
4.1. Creating the He$$oWor$d #erv$et................................................................................12
4.2. -ep$oying 5He$$oWor$d5............................................................................................134.2.1. Creating the directory structure...........................................................................14
4.2.2. Creating the Conte6t -escriptor *i$e...................................................................1&
4.2.3. Creating a e.6m$ *i$e *or the e app$ication.................................................1(4.2.4. Copying the serv$ets 7#)s and support *i$es to their respective directories.......1+
4.3. #aying 5He$$oWor$d5.................................................................................................1+
4.4. -ep$oying 7ava #erver )ages.....................................................................................1/Chapter &. Administering Tomcat.........................................................................................21
&.1. The Administration Too$ We Appp$ication.............................................................21
&.2. The 8anager We App$ication..................................................................................23
&.3. #tatus We App$ication..............................................................................................23Chapter (. Customi9ing Tomcat...........................................................................................2&
(.1. -isa$e -irectory !isting...........................................................................................2&
(.2. Custom -e*au$t )ages................................................................................................2((.3. Custom :rror )ages....................................................................................................2(
Chapter +. Tomcat Rea$ms....................................................................................................2+
+.1. :6ercise "vervie.....................................................................................................2++.2. 7-;C Rea$m...............................................................................................................2/
+.2.1. Insta$$ and #etup the -ataase............................................................................2/
+.2.2. Insta$$ the 7-;C -river.......................................................................................20+.2.3. #etting %p The -ataase Ta$es.........................................................................20
+.2.4. Test The 7-;C -river and Connection..............................................................3
+.2.&. -ep$oy and Test the We App$ication................................................................3
+.2.(. )repare the ecessary !ogin and :rror HT8!
-
8/12/2019 Manual Tomcat
2/60
Chapter /. Integrating Tomcat & and Apache 2....................................................................3/
/.1. %sing mod>@2...........................................................................................................3//.1.1. etting the mod>@2 connector...........................................................................3/
/.1.2. #erver :nvironment and #ystem Re,uirements..................................................3/
/.1.3. :6ercise "vervie..............................................................................................30
/.1.4. ;ui$ding mod>@2................................................................................................4/.1.4.1. Insta$$ Tomcat and veri*y that it is or@ing proper$y..................................4
/.1.4.2. Insta$$ Apache 2 and veri*y that it is or@ing proper$y...............................4
/.1.4.3. #hutdon oth Tomcat and Apache............................................................4/.1.4.4. -on$oad compi$e and insta$$ the mod>@2 source *i$es............................4
/.1.&. :dit Con*iguration
-
8/12/2019 Manual Tomcat
3/60
Chapter 1. Revision History
Table 1-1. Revision History Table
18 June 2004Revised web application deployment section completely, based on discussions
and contributions from Josh Rehman
18 June 2004 Updated version numbers of Tomcat in document
1! June 2004 "dded inte#ration with apache usin# Reverse $ro%y section
1! June 2004 "dded contribution by "ndrew &lute on buildin# mod'()2 on R*+ -
1! June 2004 "dded contribution by $atricia .arsten on usin# the Tomcat /eployer on +clipse
1! June 2004 &reditin# Trevor utler for resolvin# mod'()2 issues on andra)e
1! "pril 2004 &orrected ()2shm section
1 "pril 2004Updated mod'()2 procedure for new 204 release $lease don3t use v202 for
mod'()2 if you can help it
21 arch 2004 "dded "ppendi% "lternative &onte%t /eployment ethod for Tomcat
1 arch 2004 "dded "ppendi% " 404 +rror problems with andra)e "/56 server
22 7ebruary
2004&ompleted J/& Realm section
22 7ebruary2004
7irst edition inpro#ress uploaded
19 /ecember
200-Reformatted document in docboo) format for sin#lesource publishin#
12 ay 200- :nitial Release of Tomcat 4
-
8/12/2019 Manual Tomcat
4/60
Chapter 2. Introduction
Tomcat, sometimes )nown as "pache Tomcat, sometimes as Ja)arta Tomcat, is a Java servlet
en#ine that is the reference implementation used by ;un for its Java servlet and J;$
specifications
2.1. Why Am I Writing This ?
" few years a#o, when : was wor)in# for a company that was an : business partner, one of
the thin#s : loved about : software products was the uides and other documentation were for but it did help new users #et productive ?uic)ly,
and without scarin# them too much
The Ja)arta #roup produces a lot of documentation for Tomcat, but none of it seemed to be as
soothin#ly simple to read as the BU >eneral $ublic icense as published by the 7ree ;oftware 7oundation@ either version 2
of the icense, or Cat your optionD any later version This document is distributed in the hope
that it will be useful, but E:T*FUT "BG E"RR"BTG@ without even the implied warranty of
+R&*"BT"::TG or 7:TB+;; 7FR " $"RT:&U"R $UR$F;+ ;ee the >BU >eneral $ublic
icense for more details
2.3. What is Tomcat ?
"ccordin# to its website, httpHAA(a)artaapacheor#Atomcat, "pache Tomcat is
-
8/12/2019 Manual Tomcat
5/60
2.4. Why ho!"d I #se It ?
: #et as)ed this ?uestion a lot There are faster servlet en#ines, and there are servlet en#ines
that are easier to administer, install, confi#ure and deploy There are - reasons why : use
Tomcat H
1 :t is free 7ree for commercial and noncommercial use under the "pache license This
means that if : need a server application to crunch data, and :3m wor)in# in a lar#e
corporation with no bud#et for software for my department, : can still #et this done,
le#ally
2 :t has a lar#e installed base of users This can be a real bonus, especially when you run
into trouble &hances are, someone somewhere has already encountered, and probably
fi%ed the problem you are facin# :f you are usin# proprietary software, people are not
so willin# to share e%pertise and you will probably end up shellin# out money to resolve
issues
- :t is a reference implementation Typically people e?uate this with
-
8/12/2019 Manual Tomcat
6/60
2.&. Tested '"at(orms
: have tested the instructions in this document on the platforms below
Table 2-2. Teste! latforms
"peratin#
SystemJava $evelopment %it Tomcat Version &pac'e Version
7edora &ore 2 : Java 2 v 141 ;R2 02 2049
7edora &ore 1 : Java 2 v 141 ;R1 018 2048
(f you are usin# Tomcat version ).0.24* up#ra!e no+ to ).0.2)* or apply t'e
'otfi, on t'e Jaarta site. T'ere is a problem +it' session 'an!lin# in ).0.24 t'at
is resolve! by t'e 'otfi, an! t'e latest version of Tomcat.
(f you are usin# e!ora /ore 2* you +ill nee! to install t'e up#ra!e ernel-2..-1.42or better. T'e stoc i ernel t'at comes +it' t'e /2 !istribution +ill 'an# your
system +'en anyt'in# Java is run on it. /'ec your local yum repository for latest
up!ates.
-
8/12/2019 Manual Tomcat
7/60
Chapter 3. Installing Tomcat
This chapter covers downloadin# and installin# the Tomcat binaries on a inu% system
3.1. 'rere)!isites
efore we be#in, we will need to have a Java 2 ;/. installed This document is based on the
: Java 2 ;/. v 141 Eith Tomcat , because of dramatic chan#es in inu% in the last year,
there are a few thin#s you will need to be aware of
:f you are usin# Red *at 9, 7edora &ore or any inu% distribution that uses the B$T CBative
$F;:6 Thread ibraryD, you may have problems #ettin# Java to run properly :f you3re #ettin#
fre?uent se#mentation faults, you mi#ht want to turn off B$T y advice is to #et the latest
versions of everythin#, that is, install version 141 of the Java 2 ;/. or better, and #et the 2
inu% )ernel for superior performance
: will not cover the installation of the Java ;/. here : have a writeup on this and how you
can turn off B$T at this location
There are si#nificant differences between Tomcat 4 and Tomcat
3.2. *o+n"oading The o(t+are
Gou can find the Tomcat binaries at H httpHAA(a)artaapacheor#AsiteAbininde%c#i;croll to the
bottom of the pa#e to find the lin)s for Tomcat %, 4% and the web server connectors
Eith Tomcat , there are now ! files available for download :f you are runnin# inu%AUB:6, the
pac)a#e you are loo)in# for is the tarball, which at the time of this writin# is 018 tar#I &lic)
on the lin) and your download should start automatically
http://www-106.ibm.com/developerworks/linux/library/l-web26/index.htmlhttp://linux-sxs.org/programming/ibm-java.htmlhttp://jakarta.apache.org/site/binindex.cgihttp://jakarta.apache.org/site/binindex.cgihttp://www-106.ibm.com/developerworks/linux/library/l-web26/index.htmlhttp://linux-sxs.org/programming/ibm-java.htmlhttp://jakarta.apache.org/site/binindex.cgi -
8/12/2019 Manual Tomcat
8/60
Table 3-1. Tomcat ) aca#es as at 14 ebruary 2004
aca#e ame "peratin# System Remars
(a)artatomcat
02tar#IUB:6Ainu%
This is the base Tomcat pac)a#e Theservlet en#ine and startup scripts are in this
pac)a#e
(a)artatomcat02
deployertar#IUB:6Ainu%
This is the Tomcat /eployer pac)a#e The
deployer is for easily deployin# and
undeployin# web applications, especially if
you are usin# an :/+ ;ee the "ppendi% for
inte#ratin# the deployer with +clipse
(a)artatomcat02
embedtar#IUB:6Ainu%
This is the embedded Tomcat pac)a#e
T/K
(a)artatomcat02e%e icrosoft Eindows
This is the installer for icrosoft Eindows
This probably wor)s on BT4A2000A6$ Bot so
sure about 9A98A+ :f you )now, please
email me
(a)artatomcat02Iip,
(a)artatomcat02
deployerIip, (a)arta
tomcat02embedIip
EindowsAUB:6Ainu%
Gou can use this Iip file on UB:6Ainu%, but
you will have to remember to set the
permissions properly before it will wor)
Ehy #o to all that troubleL Just use the tar
pac)a#e
:f you are usin# Eindows, you have a choice of either the Iip file or the +6+ file : haven3t tried
runnin# Tomcat on Eindows, so : cannot say anythin# else about it
3.3. Insta""ing The o(t+are
There are many ways that you can #et Tomcat installed on your inu% system Gou could use the
rpm3s that are now available on(pac)a#eor#or the tarballs from the Ja)arta site This
document covers only the Ja)arta tarballs : have never used the rpm pac)a#es before
:f you have already downloaded the binary, simply copy it to the directory you want to install it
under and e%pand the file 7or e%ample, if : downloaded the Tomcat tar file into
/home/someuser/downloadsand wanted to install it under /opt, here is what : would do "sroot userH
#cp /home/someuser/downloads/jakarta-tomcat-5.x.xx.tar.gz /opt
#tar -zxvf jakarta-tomcat-5.x.xx.tar.gz
" directory called (a)artatomcat%%% will be created and the Tomcat files will e%pand under
it
mailto:[email protected]://www.jpackage.org/mailto:[email protected]://www.jpackage.org/ -
8/12/2019 Manual Tomcat
9/60
$reviously, : would have recommended that the jakarta-tomcat-5.x.xxdirectory be
renamed to (ust tomcat *owever, because : e%pect Tomcat to be updated more fre?uently
for now, since it has only (ust been released, : would instead recommend creatin# a symbolic
lin) to a tomcatdirectory
#ln -s jakarta-tomcat-5.0.25 tomcat
:n order for Tomcat to startup and shutdown, you will also need to add an environment variable
pointin# to the Tomcat directory C&"T":B"'*F+D, and one variable pointin# to your Java ;/.
directory CJ"5"'*F+D : will ma)e the followin# assumptionsH
J"5"'*F+
Java is installed into /opt/IBMJava2-141
&"T":B"'*F+
Tomcat is installed into /opt/jakarta-tomcat-5.x.xxand symlin)ed to
/opt/tomcat
:nsert the followin# lines inside /etc/pro!leor /root/."ashrc
export JAVA_HOME=/opt/IBMJava2-141
export CATALINA_HOME=/opt/tomcat
Bow, save the file and reboot the system to ensure that all chan#es ta)e effect
3.4. tarting and topping Tomcat
efore we be#in, we will need to ensure that &"T":B"'*F+ and J"5"'*F+ are correctly
set To do this, we open a terminal and type the followin# H
#echo $CATALINA_HOME
#echo $JAVA_HOME
:f you #et a blan) line, or if the directory points anywhere besides where it is supposed to, you
will have to correct these environment variables first, before continuin#
:f everythin# is fine, you can start Tomcat with the followin# command "s root,
#$CATALINA_HOME/bin/startup.sh
To chec) if Tomcat is runnin# fine, you should open a browser and point the UR to
httpHAAlocalhostH8080 Gou should see the default Tomcat welcome pa#e :t would be a #ood
idea, at this point, to browse the documentation or try out the e%ample servlets and Java;erver
$a#es samples
-
8/12/2019 Manual Tomcat
10/60
To stop Tomcat, as root,
#$CATALINA_HOME/bin/shutdown.sh
:f Tomcat does not start and you downloaded the Iip file, the cause is probably due to
permissions +nsure that the followin# files are e%ecutable H inside #$%&%'I(%)*+M,/"!ndirectory,
#chmod +x startup.sh
#chmod +x shutdown.sh
#chmod +x tomcat.sh
"fter you have made the files e%ecutable, try startin# and stoppin# Tomcat a#ain
3.$. !nning Tomcat as -onoot #ser
: don3t believe there any issues with runnin# Tomcat as root user *owever, for the moresecurityconscious readers out there, here are some instructions on runnin# Tomcat as a non
root user
"t this sta#e, the Tomcat pac)a#es, files and binaries are owned by root Ee will first need to
create a Tomcat user and #roup that will own these files, and under which Tomcat will run
Tomcat ser 55tomcat
Tomcat 6roup 55tomcat
Bot too ima#inative, huh L Ee will now create the Tomcat user and #roup Fpen a terminal
window and, as root,
#groupadd tomcat
#useradd -g tomcat -d /opt/tomcat tomcat
#passwd tomcat
Botice that we specified the home directory of Tomcat to be AoptAtomcat ;ome people believe
that this is #ood practice because it eliminates an additional home directory that needs to be
administered
Bow, we will put everythin# in AoptAtomcat under Tomcat user and #roup "s root,
#chown -R tomcat:tomcat /opt/tomcat
:f /opt/tomcatis a symlin) to your Tomcat install directory, you3ll need to do thisH
#chown -R tomcat:tomcat /opt/jakarta-tomcat-5.x.xx
-
8/12/2019 Manual Tomcat
11/60
5erify that J"5"'*F+ and &"T":B"'*F+ environment variables are setup for tomcat user,
and you should be #ood to #o Fnce the Tomcat binaries are under Tomcat user, the way you
invo)e it will be different
To start Tomcat,
#su - tomcat -c /opt/tomcat/bin/startup.sh
To stop Tomcat,
#su - tomcat -c /opt/tomcat/bin/shutdown.sh
"lso, be aware that your web applications will need to be deployed Cie copied to the web
application directoriesD as user tomcat, instead of root " little more hassle, but possibly a little
safer too
-
8/12/2019 Manual Tomcat
12/60
Chapter 4. Deploying We !pplications
" Java servletAJ;$ en#ine is not really useful without servlets and J;$s, and deployin# servlets
can sometimes be a difficult and errorprone process, because, in addition to writin# and
compilin# the servlet, you will need to edit at least 2 6 files to #et the servlet properly
deployed : will cover the manual method here, but there are other ways, such as usin# the
ana#er Eeb "pplication or developin# an "nt build process There is also a deployer pac)a#e
that you can download : don3t )now how to use it thou#h :f you do )now, please email meM
Ee will write and compile a simple
-
8/12/2019 Manual Tomcat
13/60
}///:~
Bow, we save the file as *elloEorld(ava and compile it *ere, you will find the first of several
differences between Tomcat 4 and Tomcat
:f you3re li)e me, you normally use the servlet classes supplied by Tomcat to compile your
servlets, ta)e note that the filename of the pac)a#e has chan#ed H it is now called servlet-
ap!.jar, not servlet.jar, as it was previously C "m : wron# L et me )now MD
:f you don3t )now what :3m tal)in# about, (ust compile the servlet usin# the followin# commandH
#javac -classpath $CATALINA_HOME/common/lib/servlet-api.jar
HelloWorld.java
To avoid havin# to )ey in the
-
8/12/2019 Manual Tomcat
14/60
4.2.1. Creating the directory structure
efore you be#in deployment, you will need to create a directory structure under the
#$%&%'I(%)*+M,/we"appsdirectory that conforms to the servlet specifications 7or our
e%ample
-
8/12/2019 Manual Tomcat
15/60
:B7Alib drivers, they should be copied here
To illustrate this #raphically, our final web application should be laid out as shown belowH
/irectory structure of a new web application
4.2.2. Creating the Conte"t Descriptor #ile
T'is section 'as been revise! an! is !ifferent from ol!er versions of t'is !ocument. See
t'is &ppen!i,for an e,planation of t'e c'an#es.
The conte%t descriptor file, accordin# to the Tomcat official documentation, is
-
8/12/2019 Manual Tomcat
16/60
Tomcat server confi#uration "n added benefit is that web applications deployed in this way do
not re?uire a stop and restart of the Tomcat server process Tomcat should automatically pic) it
up while it is still runnin#
4.2.3. Creating a $e."ml #ile #or the $e application
The file web%ml is sometimes )nown as a deployment descriptor, and it is basically the
confi#uration file for your web application :n this file, you determine, amon# other thin#s H
the UR of the servlets in your web application
the authentication method you wish to use
Gour filter definitions
7or now, we will simply re#ister *elloorldas a servlet in the web application called
M!rst Ee create a new we".xmlfile with the followin# contents inside it H
HelloWorld
HelloWorld
HelloWorld
/HelloWorld
Gou will notice that we had to do two thin#s here H
"ssociate the servlet class file Cin this case, *elloEorldclassD with a handlerC*elloEorldD
/efine how the servlet is accessed via a UR
:n previous releases of Tomcat, if you did not define the Nservletmappin#O element, you could
still invo)e the servlet by typin# httpHAAhostnamedomaincomAy7irstAservletA*elloEorld "s of
version 4118, this option is turned off, and you will have to define your servlet3s UR:
-
8/12/2019 Manual Tomcat
17/60
:n the we".xmlfile we (ust created, we told Tomcat that the servlet called *elloorld.class
is referred to as *elloorld, and that the UR by which this servlet is to be referred to is
httpHAAhostnamedomaincomH8080Ay7irstA*elloEorld
4.2.4. Copying the servlets% &'(s and support #iles to their respective
directories
Bow we can copy the Java class file that we compiled earlier, into the deployment directory
ecause this is a servlet, it will #o into #$%&%'I(%)*+M,/we"apps/M!rst/,B-
I(/classesdirectory There is no need to copy the source file into that directory
7or more complicated deployments, such as servlets that re?uire additional classes, such as
J/& drivers, or libraries, these additional files must be stored inside the /,B-I(/l!"
subdirectory of the web application directory :f you wish to ma)e these libraries available to all
web applications in Tomcat, save them inside #$%&%'I(%)*+M,/common/l!"/directory
7or Java;erver $a#es CJ;$sD, the P(sp files #o in the same directory as the static *T files,
that is, under #$%&%'I(%)*+M,/we"apps/M)e")%ppl!cat!on/
4.3. aying 0/e""oWor"d0
Testin# your servlet
Ee are now ready to test our *elloEorld servlet ;ince this is the first servlet we are testin#,
and we are not really sure what we will see, : stron#ly advise #oin# into 6 Eindows and openin#
several terminal windows to display error and information messa#es, as they occur *ere3s how
we3re #oin# to test and see if our Tomcat deployment can indeed say
-
8/12/2019 Manual Tomcat
18/60
#cd $CATALINA_HOME/logs
#tail -f localhost_log.YYYY-MM-DD.txt
substitute GGG// with the date Cfor e%ample H 200-0211D
"s Tomcat starts up, you can see the messa#es it writes to the 2 lo# files C3tail f3 opens theterminal window in a )ind of console mode, so you can see events as they happenD :f there are
any errors, they will be reflected, sometimes in a very verbose fashion Ta)e note of the errors,
if there are any, and report them on the mailin# list, if you cannot solve it yourself
:f Tomcat started without errors Cor even if it did have errorsD, we can test the servlet with our
browser
/'ecin# +it' a bro+ser
1 Fpen Betscape or oIilla on the local machine
2 7or the UR, )ey in H httpHAAlocalhostH8080Ay7irstA*elloEorld
- Gou should see a web pa#e that says, very emphatically,
-
8/12/2019 Manual Tomcat
19/60
-
8/12/2019 Manual Tomcat
20/60
#cd $CATALINA_HOME/bin
#./jspc.sh $CATALINA_HOME/webapps/MyFirst/index.jsp
-
8/12/2019 Manual Tomcat
21/60
Chapter ). !dministering Tomcat
There are three administration tools bundled with Tomcat They areH
;erver ;tatus application
Tomcat "dministration Tool
Tomcat ana#er
These web applications are bundled with Tomcat by default and can be accessed from the left
sidebar of Tomcat3s default pa#e These tools address the need for simplified administration
which other servlet en#ines, such as Eebsphere or Eeblo#ic, provide
$.1. The Administration Too" We Appp"ication
The "dministration Tool web application is the >U: tool for administerin# Tomcat efore we can
use it, or any of the >U: tools, we will first need to create a Tomcat administrator account, a
Tomcat mana#er account and two rolesH
-
8/12/2019 Manual Tomcat
22/60
;ave the file, start Tomcat and open a browser Gou should be able to access the "dministartion
Tool web application by clic)in# on the U: "n e%ample of this >U:
is shown below The "dministration Tool has collapsible menus on the left &lic) on any of the
icons in the left pane to display information and settin#s in the ri#ht pane /ependin# on the
specifications of your server, the display of settin#s and information in the ri#ht pane can be
very slow M Gou have to be patient and restrain your ur#e to )eep clic)in# if the system seems
unresponsive
Tomcat "dministration Tool
-
8/12/2019 Manual Tomcat
23/60
$.2. The anager We App"ication
Gou can access the ana#er Eeb "pplication by clic)in# the U: that allows you to view the status of
your installed web applications and even deploy new web applications There is also a lin) to the
-
8/12/2019 Manual Tomcat
24/60
;tatus Eeb "pplication
-
8/12/2019 Manual Tomcat
25/60
Chapter *. Customi+ing Tomcat
This section e%plores some of the ways you can control the way Tomcat operates This is not
e%haustive Tomcat is e%tremely sophisticated software and there are a lot of thin#s you can
chan#e or twea)
&.1. *isa"e *irectory Listing
7or fresh Tomcat installations, directory listin# is enabled by default This can be a very useful
debu##in# tool, and if, li)e me, you sometimes for#et what servlets are deployed in a certain
web application, you can #et a complete listin# by simply )eyin# in the web application3s UR
ut for production deployments, you may want to turn it off :f nothin# else, it discoura#es users
from po)in# around where they should not There are basically 2 methods of
-
8/12/2019 Manual Tomcat
26/60
This is the first section in web%ml The options that concern us are H
listings
true
&han#e NparamvalueO to false and you turn off directory listin# :t is that simple
&.2. C!stom *e(a!"t 'ages
Tomcat uses the same convention as the "pache Eeb ;erver in that inde%html is the default or
home pa#e of any directory ;ometimes you may want to chan#e that to pa#e1html or maybe a
J;$ pa#e, li)e now'see'this(sp
To do that, simply open the web%ml of your web application, and add the followin# lines H
now_see_this.jsp
page1.html
index.html
To chan#e it systemwide, edit the #lobal web%ml in #$%&%'I(%)*+M,/con, and chan#e the
NwelcomefileO to point to the file of your choice
&.3. C!stom rror 'ages
Unhappy with the default error pa#es that come with Tomcat L Gou can define your own custom
error pa#es in your we".xmlfile :n the e%ample shown below, we define 2 web pa#es
server)error.htmland !le)not)ound.html which will be displayed when the server
encounters an error 00 or an error 404 respectively
500
/server_error.html
404
/file_not_found.html
Gou should bear in mind, however, that the order of the ta#s for the web%ml file is very
important :f the order in your web%ml file is incorrect, Tomcat will output errors on startup
-
8/12/2019 Manual Tomcat
27/60
Chapter ,. Tomcat Realms
;ometimes, you need to protect your web pa#es andAor web applications, so only re#istered
users can #et access to them To most endusers, they understand this as the lo#in pa#e of the
website To some technical professionals, this is )nown as the authentication facility
" realm is a collection of pa#es, ima#es and applications Ccollectively )nown as
-
8/12/2019 Manual Tomcat
28/60
Fnce you have wor)ed throu#h this e%ample, : am hopin# that you will also be able to infer the
steps for your own particular setup
5.2. *7C ea"m
This type of realm involves storin# the credentials of your users Cie their usernames, passwordsand assi#ned rolesD inside a database Tomcat will then need to be confi#ured to use this
database and the J/& realm option inside the confi#uration files will need to be enabled
;ettin# up a J/& Realm involves the followin# stepsH
1 :nstall and ;etup The /atabase
2 :nstall the J/& /river
- ;etup the /atabase Tables
4 Test The J/& /river and &onnection
/eploy and Test the Eeb "pplication
$repare the Becessary o#in and +rror *T 7iles
! +dit Tomcat3s server%ml To +nable J/& Realm
8 +dit the Eeb "pplication3s web%ml To Re?uire "uthentication
9 ;tart Tomcat and Test
7or this e%ercise, : shall be buildin# on my 7irebird v 1 for inu% article Gou can use any
database product you li)e, as lon# as it provides a J/& driver Cyou could use an F/& driver
and a J/&F/& driver, but you may want to reconsider this for production deploymentsD The
;= synta% may also differ, so you should e%pect some differences between my instructions and
your own re?uirements
,.2.1. Install and 'etup the Dataase
To use the J/& realm, you will need to have a database to store your user credentials :f you
have not already done so, install a database, or use an e%istin# database on your server or
networ) This document will not cover the installation of database products
Gou will also need to ensure that your database can startup and shutdown, and you should be
reasonably familiar with operations on the database you have chosen : will not cover these
aspects here
:f you are a icrosoft ;= ;erver user, : cannot help you : do not use that product, and : hear
that there are all sorts of problems accessin# it with a J/& driver : personally prefer 7irebird,
because of its compact siIe and because it is free
http://cymulacrum.net/writings/firebird15/book1.htmlhttp://cymulacrum.net/writings/firebird15/book1.html -
8/12/2019 Manual Tomcat
29/60
,.2.2. Install the &D-C Driver
"s : mentioned earlier, you will need a suitable J/& driver to connect to your database product
: say
-
8/12/2019 Manual Tomcat
30/60
user9name :varc'ar;2)< not null= role9name :varc'ar;20< not null=
isabellec mana#er
isabellec tomcat
daytonr mana#er
daytonr tomcat
aIleaa tomcat
primary ey ;username* rolename<
: will not cover the ;= statements re?uired :f you need hints, please read my 7irebird article,
which covers the creation of the two tables, but only for 7irebird
Botice that : specified - different roles here H admin, mana#er and tomcat The admin and
mana#er roles are builtin roles for Tomcat, that allow access to the ana#er web application
and the Tomcat "dministration Tool Ee can actually test if our J/& realm wor)s later by
seein# if user
-
8/12/2019 Manual Tomcat
31/60
*ere is the lo#in pa#e for this e%erciseH
Login Page
Login to MyFirst
If you have been issued a username and password, key them in here now!
Username :
Password :
Bote the form elements The form action is
-
8/12/2019 Manual Tomcat
32/60
-
8/12/2019 Manual Tomcat
33/60
aramet
er ame
server.,ml
e?uivalentarameter Value Remars
application
J/&
&onnectio
n UR
connectionUR(dbcHfirebirds?lHlocalhostA-00HAoptAfirebirdAdbAreal
mdbfdb
To find out
the synta%
and values of
your
connection
UR, refer to
your J/&
driver
documentatio
n
/atabase
lo#in
name
connectionBame ;G;/"
This is the
usernameyou use to
lo#in to the
database
containin#
the realm
users3
credentials
/atabase
lo#in
password
connection$assw
ord password
This is the
lo#in user3s
password
User
TableuserTable tcusers
Table
containin# list
of authoriIed
users for the
realm
Bame
&olumn of
User
Table
userBame&ol user'name
The name of
the column
containin#
the list of
users inside
the UserTable
User
$assword
&olumn of
User
Table
user&red&ol user'pwd The name of
the column
containin#
the
respective
-
8/12/2019 Manual Tomcat
34/60
aramet
er ame
server.,ml
e?uivalentarameter Value Remars
user3s
password in
the UserTable
Role Table userRoleTable tcroles
Table
containin#
the list of
users and
their
respective
roles
Role
Bame
&olumn
roleBame&ol role'name
The name of
the columncontainin#
the user3s
assi#ned
roles
Eith this information, we can form the followin# re?uired stanIa for the J/& realmH
,.2.5. dit the We !pplications $e."ml To Re6uire !uthentication
Ee need to confi#ure the web application to re?uire authentication as well "t this sta#e, we
determine which resources to protect, who has access, and how we want to protect these
resources That is, we define the directories andAor the files to protect Chtml, (sp, ima#e files or
all filesD, which role has access and which type of authentication we want to use C7ormbased,
asic, &ustom or /i#estD
7or this e%ercise, this is what we want to protectH
+verythin# in the y7irst application, that is, all *T files, ima#e files, J;$ files,
servlets, te%t files, everythin#M
-
8/12/2019 Manual Tomcat
35/60
"ny and all access methods, that is, *TT$ >+T, $UT, $F;T, /++T+, will #et the lo#in
prompt
Eho can access itH
Fnly users with the 3tomcat3 role are allowed to access the y7irst web application
*ow we want to protect the resourcesH
Ee will use 7ormbased authentication
The lo#in pa#e is lo!n.html
The error pa#e, if the user )eys in the wron# username or password is autherr.html
Ee also need to define the roles that will have access 7or this e%ercise, we only want users with
the 3tomcat3 role to have access
To e%press these re?uirements, we )ey in the stanIa below into the web application3s we".xml
file, after the Nservletmappin#O section and before the terminatin# NAwebappO ta#
MyFirst
accessible by authenticated users of the
tomcat role
/*
GET
POST
PUT DELETE
These roles are allowed access
tomcat
FORM
MyFirst Protected Area
/login.html
/autherr.html
Only 'tomcat' role is allowed to access this web
-
8/12/2019 Manual Tomcat
36/60
application
tomcat
T'e or!er of t'e sections is important@ (f you #et errors on Tomcat startup* it may be
!ue to t'e or!erin# of your sections. or e,ample* t'e Asecurity-constraintB sectioncan "CD come after t'e Aservlet-mappin#B section. or more !etails on t'e proper
or!er* rea! t'e Servlet Specifications !ocument.
Bow, we are finally ready to test our J/& realm M
,.2.7. 'tart Tomcat and Test
5erify that the lo#inhtml and autherrhtml files are in the y7irst web application directory Gour
Tomcat en#ine should be stopped at this time ;tart Tomcat and open a browser Try to access
the *elloEorld servlet Gou should #et redirected to the lo#in pa#e Csee belowD
.ey in the username and password of a user who does PnotP have the tomcat role Gou should
#et the error pa#e
http://jcp.org/aboutJava/communityprocess/final/jsr154/index.htmlhttp://jcp.org/aboutJava/communityprocess/final/jsr154/index.html -
8/12/2019 Manual Tomcat
37/60
Be%t, )ey in the username and password of a user who has the 3tomcat3 role, and clic) the o#in
button Gou should then see the familiar *elloEorld servlet pa#e
-
8/12/2019 Manual Tomcat
38/60
Chapter 5. Integrating Tomcat ) and !pache 2
There are two ways Cthat : )now ofD to inte#rate Tomcat with "pache 2H
"pache can be confi#ured to pro%y re?uests sent to Tomcat
"pache can pass re?uests to Tomcat via connectors such as mod'()2
8.1. #sing mod9:;2
: don3t )now if mod'() still wor)s for Tomcat : do )now that mod'webapp development
seems to have lapsed, so : shall concentrate on mod'()2 inte#ration :f you )now of other
methods of inte#ratin# Tomcat and "pache, please let me )now M
5.1.1. 8etting the mod9:;2 connectorT'e Jaarta #roup release! version 2.0.4 of t'e mo!9E2 connector on 2 Farc' 2004.
T'is release inclu!es source paca#es an! RF paca#es for e!ora /ore 1* Suse G an!
Suse SC7S . ( +ill only be coverin# t'e source paca#e compilation on e!ora /ore for
t'is !ocument.
>inary RF paca#es are available for e!ora /ore 1* SS7 G.0 an! SS7 SC7S at t'e
Jaarta !o+nloa! site or mirrors. (m not #oin# to be coverin# t'e RF paca#es in
t'is !ocument.
T'is release cleans up a lot of t'e bu#s an! annoyances t'at use! to pla#ue users of
t'e previous release. (ts actually ?uite #oo! -- but t'en* Henri 6omeI !oes #oo!+or @
The source pac)a#e cannot be accessed directly from the lin)s on the Ja)arta site Cstran#ely
enou#hMD "nd because the Ja)arta site will redirect you to the nearest mirror, the location of the
source pac)a#e may vary from site to site y local mirror has the source tarball in this locationH
httpHAAapacheosseInetsolsor#A(a)artaAtomcatconnectorsA()2AsourceA
:f you clic)ed on the lin) for the J.2 inary Releases on the Ja)arta site, you will need to clic) on
-
8/12/2019 Manual Tomcat
39/60
Table -1. Server /omponents
Cinu,
$istributionJava Virtual Fac'ine
&pac'e
version
Tomcat
version
mo!9E2
version
7edora &ore 1: Java 2 ;/. v141
;R12048 018 204
The followin# libraries were also installedH
aprutil0942
apr0942
aprutildevel0942
aprdevel0942
automa)e1!81
autoconf2!-
m414114
libtoollibs18
libtool18
pcre441
pcredevel441
: believe that they are all re?uired for the compilation of the J.2 source pac)a#es :f you #et a
AlibAcpp sanity chec) failure when runnin# the confi#ure script, chec) that you have the followin#
installedH
libstdcQQdevel--21
#cccQQ--21
7or all the above items, : am not sure if the version matters, but these versions wor)ed for me
5.1.3. "ercise
-
8/12/2019 Manual Tomcat
40/60
(nte#ratin# &pac'e an! Tomcat +it' J%2
1 :nstall Tomcat and verify that it is wor)in# properly
2 :nstall "pache 2 and verify that it is wor)in# properly
- ;hutdown both Tomcat and "pache
4 /ownload, build and install the mod'()2 source files
+dit the confi#uration files httpd.con, jk2.propert!es, workers2.propert!es
and server.xml
;tart Tomcat
! ;tart "pache
8 5erify that everythin# wor)s
5.1.4. -uilding mod9:;2
8.1.4.1. Install Tomcat and verify that it is working properly
:nstall Tomcat and verify that all the servlet and J;$ e%amples wor) properly :f you wor)ed
throu#h the earlier sections, you should already have a wor)in# Tomcat setup
8.1.4.2. Install Apache 2 and verify that it is working properly
: am usin# the R$ pac)a#es for 7edora &ore for this e%ercise : will not be coverin# the
installation of the source tarball or other R$ pac)a#es :n any case, there are plenty of
resources and documentation available for this tas)
5erify that "pache 2 is wor)in# by startin# and stoppin# the http daemon and try to access web
pa#es on it
8.1.4.3. Shtdown !oth Tomcat and Apache
:f you are ready to build the mod'()2 binary from the source pac)a#e, you should shutdown
both Tomcat and "pache Ee will start them up momentarily, after we have finished the ne%t
step
8.1.4.4. "ownload# compile and install the mod$%k2 sorce files
:f you have already downloaded the pac)a#e, navi#ate to the download directory and unpac) the
tarball
[chongym@localhost mod_jk2]$tar -zxvf jakarta-tomcat-connectors-jk2-
-
8/12/2019 Manual Tomcat
41/60
2.0.4-src.tar.gz
Bow, you will need to navi#ate to the build directory
[chongym@localhost mod_jk2]$cd jakarta-tomcat-connectors-jk2-2.0.4-
src/jk/native2/[chongym@localhost native2]$ls
aclocal.m4 B8I'9.txt common I(:&%''.txt scr!pts
apr "u!ld.xml con!ure jn! server
autom4te.cache $*%(;,:.html con!ure.!n Make!le.!n :&%&8:.txt
"u!ldcon.sh $*%(;,:.txt !nclude
-
8/12/2019 Manual Tomcat
42/60
:f it completes successfully, you should see somethin# li)e thisH
l!"tool !nstall warn!n remem"er to run ?l!"tool --!n!sh
/usr/l!"/httpd/modules@
/"!n/cp ../../../"u!ld/jk2/apache2//usr/l!"/httpd/modules/l!"jkjn!.so
../../../"u!ld/jk2/apache2/l!"jkjn!.so
make01 'eav!n d!rector
?/home/chonm/downloads/jk2/jakarta-tomcat-connectors-jk2-2..4-
src/jk/nat!ve2/server/apache2@
Ee don3t really need to run 3libtool3, but for the sa)e of completeness, let3s e%ecute it as
su##ested by the messa#es above
0rootAlocalhost nat!ve2 l!"tool --!n!sh
----------------------------------------------------------------------
'!"rar!es have "een !nstalled !n
I ou ever happen to want to l!nk aa!nst !nstalled l!"rar!es
!n a !ven d!rectorC 'IB9I
-
8/12/2019 Manual Tomcat
43/60
chmod 55 /usr/l!"/httpd/modules/mod)jk2.so
"t this point : would li)e to e%plain a little about what ap%s is and what it does "ccordin# to the
"pache documentation, "$6; is the "$ache e6ten;ion Tool :t3s stated purpose is for buildin#
and installin# e%tension modules to "pache by buildin# /ynamic ;hared Fb(ect C/;FD files from
source files Ehat this means is that : can add e%tensions to the "pache web server withoutneedin# to recompile it
:f the apxscommand e%ecuted successfully, you should find both mod'()2so and lib()(niso
inside the current directory, which isH your_download_directory/jakarta-tomcat-
connectors-jk2-2..4-src/jk/"u!ld/jk2/apache2
Gou should then copy those two files into /usr/l!"/httpd/modules/ Bote that you will have
to rename l!"jkjn!.soto jkjn!.so
[root@localhost apache2]#cp libjkjni.so /usr/lib/httpd/modules/jkjni.so
[root@localhost apache2]#cp mod_jk2.so /usr/lib/httpd/modules/mod_jk2.so
5.1.). dit Con#iguration iles httpd.con#% :;2.properties%$or;ers2.properties and server."ml.
"t this point, you have to ma)e a choice about the type of connection channel you want to use
to connect "pache with Tomcat There are 4 types of connections
&hannel soc)ets
UB:6 soc)ets
"$R soc)ets
JB: channels
5.1.*. Con#iguring #or /I= soc;ets
: will only be coverin# the confi#uration for UB:6 soc)ets in this document
8.1.&.1. 'nvironment (aria!les
Gou will need to set one environment variable inside catal!na.sh ocate the followin# code
bloc) inside the scriptH
# Get standard environment variables
PRGDIR=`dirname "$PRG"`
CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
. "$CATALINA_HOME"/bin/setenv.sh
fi
-
8/12/2019 Manual Tomcat
44/60
"ppend below it the followin# lines and save the file
# Set serverRoot
serverRoot=/etc/httpd2
export serverRoot
Be%t, you will need to edit your confi#uration files Try not to use the default files that come with
your source download The default files have a lot of options inside them, and may not wor)
Dou FST ensure t'at &pac'e an! Tomcat 'ave been s'ut!o+n before e!itin# t'ese
files because t'ey may be over-+ritten +'en eit'er !aemon is starte!.
There are - files you will need to edit and one file you will need to chec)H
-
8/12/2019 Manual Tomcat
45/60
Table -2. /onfi#uration iles or ( socets
ilename Cocation &ction To Tae
httpd.con /etc/httpd/con/ +dit this file
jk2.propert!es /opt/tomcat/con &reate this file
workers2.propert!es /etc/httpd/con &reate this file
server.xml /opt/tomcat/con &hec) this file
8.1.&.2. httpd.conf
Gou will need to ma)e "pache2 aware of the Tomcat connector "dd the followin# lines into
httpdconf, at the end of the oadodule bloc)H
LoadModule jk2_module /usr/lib/httpd/mod_jk2.so
8.1.&.3. %k2.properties
ac)up the e%istin# ()2properties file in this directory, then create a new ()2properties
implementin# UB:6 soc)ets, as shown below H
# jk2.properties
# Configured for channel UNIX
# Set the desired handler listhandler.list=apr,request,channelUnix
# UNIX Domain socket location
channelUnix.file=/opt/tomcat/work/jk2.socket
# Dynamic Library
serverRoot=/etc/httpd
apr.NativeSo=/usr/lib/httpd/modules/jkjni.so
8.1.&.4. workers2.properties
" sample wor)ers2properties implementin# UB:6 soc)ets is shown below H
# workers2.properties
# Shared memory handling. Needs to be set.
[shm]
info=Scoreboard. Required for reconfiguration and status with multiprocess
-
8/12/2019 Manual Tomcat
46/60
serve
rs
file=/opt/tomcat/logs/jk2.shm
size=1048576
debug=0
disabled=0
# UNIX domain socket
[channel.un:/opt/tomcat/work/jk2.socket]
tomcatId=localhost:8009
debug=0
# define the worker
[ajp13:/opt/tomcat/work/jk2.socket]
channel=channel.un:/opt/tomcat/work/jk2.socket
# Announce a "status" worker
[status:status]
info=Status worker. Displays runtime information.
[uri:/jkstatus/*]
group=status:status
# Uri mapping
[uri:/examples/*]
# Uri mapping for MyFirst
[uri:/MyFirst/*]
8.1.&.). server.*ml
Gou will need to ensure that the followin# code bloc) in server.xmlis uncommented y
default, it already is, but if you have been tin)erin# with your setup, you would probably want to
chec), (ust to be sure
8.1.&.&. +heck for %k2.shm
+arlier, you defined a file jk2.shmin workers2.propert!es This file should be automatically
created when Tomcat is run ;tart Tomcat now, if you have not already done so and verify that
the file is created and is writeable by the UB:6 user that the Tomcat daemon runs under 7or
this e%ercise, that user would be 3tomcat3
-
8/12/2019 Manual Tomcat
47/60
8.1.&.,. %k2.socket -ermissions
This file is crucial for communications between "pache and Tomcat, and therefore must be
readable and writeable by both the "pache user and the Tomcat user This file is also
automatically #enerated when Tomcat starts up This file has read and write permissions for user
and #roup This means that you need to put both the "pache user and the Tomcat user in thesame #roup 7or this e%ercise, we will put 7edora3s "pache user, called 3apache3 inside the
Tomcat #roup, called 3tomcat3H
[root@localhost logs]#usermod -G apache,tomcat apache
8.1.&.8. "eploying e! Applications
7or every web application, we must supply a Uri mappin# 7or e%ample, for our y7irst web
application, we simply append to our wor)ers2properties the followin#H
[uri:/MyFirst/*]
Bow, you are ready to test ;ince both "pache and Tomcat are stopped, we will need to start
them up
5.1.,. 'tart Tomcat
7or the confi#urations defined here, the startup processes for "pache 2 and Tomcat are
-
8/12/2019 Manual Tomcat
48/60
[root@localhost run]#tail -f /var/httpd2/logs/error_log
5.1.7. >eri#y that everything $or;s
Fpen a browser and )ey in the UR 7or our web application 3y7irst3, the UR to )ey in for the
*elloEorld servlet would behttp//localhost/M!rst/*elloorld
:f you #et an error,
chec) to see if you followed the instructions closely "nother thin# to chec) are the error lo#s
:f everythin# wor)s, con#ratulations M Gou have successfully inte#rated "pache and Tomcat M
8.2. everse 'ro6y +ith Apache
:f you don3t want to mess with the comple%ities of mod'()2, but you need to put "pache in front
of Tomcat, there is an alternative, and that is to setup reverse pro%yin# in "pache
"ccordin# to the "pacheEee) website,
-
8/12/2019 Manual Tomcat
49/60
where it defines Tomcat3s server hostname in the $ro%y$ass and $ro%y$assReverse
directives and ma)e the appropriate chan#es
5.2.3. dit Tomcats server.xml
Gou will need to locate the followin# stanIa and uncomment it
Bote that in the stanIa above, we are usin# port 8082 as the reverse pro%y port for Tomcat Gou
will need to remember this when we edit "pache3s confi#uration
5.2.4. dit !paches httpd.conf
Gou need to ensure that the followin# pro%y directives inside httpd.conare uncommented
Cwhich they normally are by defaultD
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
There are actually 2 ways that you can add reverse pro%yin# to "pache The first involves usin#
the NocationO directive while the second involves settin# up a 5irtual *ost definition : will be
coverin# the second option
;uppose that we have a virtual host www.v!rao.com.s, and its :$ address is
12.1K3..2, and we want to use namebased virtual hostin#
Ee add the followin# line into httpd.conH
NameVirtualHost 192.168.0.200:80
Then we setup the virtual host stanIa li)e soH
ServerName www.virago.com.sg
DocumentRoot /var/www/html
-
8/12/2019 Manual Tomcat
50/60
-
8/12/2019 Manual Tomcat
51/60
no special lo##in# defined, the access lo# is localhost)lo.Esome)dateF.txt &hec) if any
re?uests are comin# into Tomcat :f none are, then you )now you have a networ) problem
;pea) to your networ) administrator to resolve it
-
8/12/2019 Manual Tomcat
52/60
Chapter 7. Re#erences and se#ul 0in;s
"re you usin# a different Java2 ;/., or a different "pache version L Fr maybe your deployment
is different you need virtual hostin# instead of the relatively strai#htforward method of
deployment shown here Fr maybe you (ust thin) that my writin# suc)s
Eell, there is an alternative to (ust flamin# meM There are a lot of other people who have
volunteered their time and effort, producin# ?uality documentation for Tomcat isted below are
some lin)s that you may find useful "lso, if you )now of any #ood sites, or if you want me to
lin) to your site, please email meM
7irst, some lin)s to pa#es that e%plain other deployment methods or environmentsH
Table G-1. References "n Various Tomcat $eployments
/onfi#uration $escription
Tomcat 412! Q "pache 204! Q
mod'() CR*9D
John Turner3s e%cellent *FETF for usin# mod'() instead
of mod'()2 to connect Tomcat and "pache 2 Gou can find
it here This is for Red *at inu% 9
Tomcat 4118 Q "pache 204- Q
mod'() CEindows 6$A2000D
"nother e%cellent *FETF by John Turner, this time for the
Eindows platform Gou can find it here
Eeb ;ervices with Tomcat Q "pache
Q ;truts Q $ost#re;= Q Fpen;;
Q J/&
Fscar &arrillo3s e%cellent writeup on this dauntin#
confi#uration Gou can find it here, and is well worth the
effort wor)in# throu#h it
Tomcat 40%A41% 5irtual *ostin#
>alatea3s 7lash>uides "lways useful Gou can find the
details here There are other flash#uides which you can
find here
Tomcat 41% Q "pache 2 Q
mod'()2Ja)arta site3s mini*FETF for virtual hostin#
&oncise Tomcat 41% Q ;un Java 2
;/. Q "pache 2
ichael &ardon has written a more concise article on this,
compared to my verbose one :f you3re in a hurry, he is
your man Read it here
;ome interestin# articles and reference materials on TomcatH
Java ;ervlet ;pecifications 24
Tomcat is an implementation of version 24 of the Java ;ervlet ;pecifications ;ome
?uestions are best answered by #oin# bac) to this document
FnJavacom
mailto:[email protected]://www.johnturner.com/howto/apache2-tomcat4127-jk-rh9-howto.htmlhttp://www.johnturner.com/howto/winxp-howto.htmlhttp://www.linuxjava.net/howto/webapp/http://www.galatea.com/flashguides/virtual-hosting-tomcat.xmlhttp://www.galatea.com/flashguides/indexhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/jk2/jk2/vhosthowto.htmlhttp://www.cardon.biz/docs/tomcat/http://jcp.org/aboutJava/communityprocess/final/jsr154/index.htmlhttp://www.onjava.com/http://www.onjava.com/mailto:[email protected]://www.johnturner.com/howto/apache2-tomcat4127-jk-rh9-howto.htmlhttp://www.johnturner.com/howto/winxp-howto.htmlhttp://www.linuxjava.net/howto/webapp/http://www.galatea.com/flashguides/virtual-hosting-tomcat.xmlhttp://www.galatea.com/flashguides/indexhttp://jakarta.apache.org/tomcat/tomcat-4.1-doc/jk2/jk2/vhosthowto.htmlhttp://www.cardon.biz/docs/tomcat/http://jcp.org/aboutJava/communityprocess/final/jsr154/index.htmlhttp://www.onjava.com/ -
8/12/2019 Manual Tomcat
53/60
The F3Reilly site has some really useful articles on Java and Tomcat There3s an article
on the Top Ten Tomcat &onfi#uration Tipsand one on new features in Tomcat , Ehat3s
Bew in Tomcat Gou should chec) the site periodically for new articles
The Tomcat oo) $ro(ect
This is a ;ourcefor#e pro(ect that seems to have lapsed ;ome useful information here,
nonetheless and the writin# is a lot better than mine in some places $lus, there are
translations M
Ja)arta ;ite3s Tomcat 7"=
This 7"= seems to be compiled from truly fre?uently as)ed ?uestions on the Tomcat
mailin# list
http://www.onjava.com/pub/a/onjava/2003/06/25/tomcat_tips.htmlhttp://www.onjava.com/pub/a/onjava/2004/01/28/tomcat5.htmlhttp://www.onjava.com/pub/a/onjava/2004/01/28/tomcat5.htmlhttp://tomcatbook.sourceforge.net/http://jakarta.apache.org/tomcat/faq/http://www.onjava.com/pub/a/onjava/2003/06/25/tomcat_tips.htmlhttp://www.onjava.com/pub/a/onjava/2004/01/28/tomcat5.htmlhttp://www.onjava.com/pub/a/onjava/2004/01/28/tomcat5.htmlhttp://tomcatbook.sourceforge.net/http://jakarta.apache.org/tomcat/faq/ -
8/12/2019 Manual Tomcat
54/60
!ppendi" !. mod9:;2 4?4 rror (rolem @With Help rom Trevor
-utlerA
T'is solution +as !evelope! +it' 'elp from Trevor >utler.
: have found that for certain versions of inu%, the deployment method : described for "pache
Tomcat inte#ration with mod'()2 may not wor) ;pecifically, entries in the confi#uration file
workers2.propert!esthat map web application conte%ts on Tomcat may not wor) : have
noticed this anomaly when the components described below are usedH
Table &-1. otentially roblematic /ombination "f /omponents
inu% distribution andra)e 92
"pache version andra)e3s "dvanced +%tranet ;erver
mod'()2 J$ac)a#e mod'()2 R$ pac)a#e
A.1. 'ro"em *escription
Gou #et
-
8/12/2019 Manual Tomcat
55/60
Fne solution around this is to specify each and every resource in the web application conte%t
7or e%ample, for the *elloEorld servlet and !ndex.jsp, you would need 2 UR: mappin#s in
workers2.propert!es, not (ust one
[uri:/MyFirst/HelloWorld]
[uri:/MyFirst/index.jsp]
:f you have a lot of servlets, J;$s, *T pa#es, etc, this approach may be unfeasible ;o, how
do you use wildcards in this situationL
A.3. A o"!tion
"s it turns out, specifyin# your conte%t in workers2.propert!esis not the only way to tell
"pache to route web application conte%t re?uests to Tomcat The web application conte%t can be
specified within "pache3s own confi#uration file :f you are usin# andra)e3s "dvanced +%tranet
;erver, that file would be /etc/httpd2/con/httpd2.con :f you use this approach, you
may need to delete the UR: conte%ts in workers2.propert!es
: will use the e%ample developed earlier in this tutorial ;uppose : have a *elloEorld servlet and
an !ndex.jspfile in the conte%t called M!rst : will assume that you either built the
mod'()2so and ()(niso libraries successfully, or that you downloaded and have already
successfully installed the mod'()2 R$ pac)a#e from J$ac)a#eor#
To specify the y7irst web application conte%t to "pache, we append the followin# lines to the
bottom of /etc/httpd2/con/httpd2.conH
# URI definitions
JkUriSet worker ajp13
:n some cases, you may need to enclose the conte%t definitions inside IfModule, li)e soH
# URI definitions
JkUriSet worker ajp13
Botice that this specifies a wildcard This means that a browser that re?uests anythin# from
http//doma!n.com/M!rst/, will automatically have his re?uest routed by "pache to
Tomcat
This solved the problem for me :f you )now of anythin# else that may help, or if you would li)e
to e%pand on my solution, feel free to email meM
mailto:[email protected]:[email protected]:[email protected] -
8/12/2019 Manual Tomcat
56/60
!ppendi" -. !out the changes in $e application deployment
section
Fne of the thin#s : really en(oy about Fpen ;ource software is that you can sometimes #et
useful insi#hts from people smarter and more e%perienced than yourself : had an interestin#
discussion with Josh Rehman on the relative merits of deployin# web applications usin# the
server.xmlmethod or usin# the conte%t descriptor method
Josh3s position is that the conte%t descriptor method should become the canonical method for
web application deployment for many reasonsH the unreliability of server.xmledits
propa#atin# throu#h the server, and the difficulty of removin# those conte%ts that are already
deployed
: had not considered that position before, probably because : do not run Tomcat in a hi#h
volume, missioncritical environment Thin#s are different in the little corner of "sia where : stay
and wor) The traffic is much lower and you can pretty much reboot the server anytime you
wish ;o brin#in# down the Tomcat server process to add, modify or delete a conte%t is feasible
:f, however, you have responsibilities for a lar#e deployment of Tomcat servers, or (ust a Tomcat
server runnin# in a hi#h volume environment, the #ame chan#es fundamentally Gou will need
somethin# that allows for
-
8/12/2019 Manual Tomcat
57/60
!ppendi" C. -uilding mod9:;2 on Red Hat nterprise 0inu" 3 BRH0
@Contriuted y !ndre$ CluteA
T'is solution +as contribute! by &n!re+ /lute. T'e actual te,t of t'e email 'as
been a!apte! for instructions.
These steps apply to a stoc) R*+ install and mod'()2 version 204 $lease refer to the chapter
on --with-apr-lib=/usr/lib \
> --with-tomcat-41=$CATALINA_HOME \
> --with-java-home=$JAVA_HOME \
> --with-jni
2. "fter confi#ure e%ecutes successfully, you will need to to modify the a)efile inside./server/apache2 ocate the followin# bloc)H
ifdef APR_LIBDIR_LA
JK_LDFLAGS=-L${APACHE2_LIBDIR} -lcrypt
else
JK_LDFLAGS=-lcrypt ${APR_LIBS}
endif
"nd chan#e it to thisH
ifdef APR_LIBDIR_LA
JK_LDFLAGS=-L${APACHE2_LIBDIR} -lcrypt
else
JK_LDFLAGS=-lcrypt ${APR_LIBS} -laprutil-0
endif
Bote the addition of -laprutil-0in the second line
3. Gou can now runmakeas root user
4. "fter ma)e completes, chec) that the file l!"jkjn!.sois built with the necessaryshared libraries To do this, run ldda#ainst that file Gou should see somethin# li)e thisH
[root@localhost modules]#ldd libjkjni.so
l!"crpt.so.1 GL /l!"/l!"crpt.so.1 Ex"5eF
-
8/12/2019 Manual Tomcat
58/60
l!"apr-.so. GL /usr/l!"/l!"apr-.so. Ex"5F
l!"aprut!l-.so. GL /usr/l!"/l!"aprut!l-.so. Ex"5KaF
l!"c.so.K GL /l!"/tls/l!"c.so.K Ex"4>1F
l!"rt.so.1 GL /l!"/tls/l!"rt.so.1 Ex"41dF
l!"m.so.K GL /l!"/tls/l!"m.so.K Ex">"F
l!"nsl.so.1 GL /l!"/l!"nsl.so.1 Ex">eKF
l!"dl.so.2 GL /l!"/l!"dl.so.2 Ex">e>F
l!"pthread.so. GL /l!"/tls/l!"pthread.so. Ex">d>F
l!"d"-4.1.so GL /l!"/l!"d"-4.1.so Ex">1F
l!"expat.so. GL /usr/l!"/l!"expat.so. Ex"2F
/l!"/ld-l!nux.so.2 GL /l!"/ld-l!nux.so.2 Ex3F
The critical library is l!"aprut!l-.so.which must appear when you e%ecute ldd
:f you see the output above, yourmakeprocess was successful Gou will need to run the
apxstool a#ainst mod'()2so and copy that file and lib()(niso to the modules directory
of your "pache install
&. :f yourmakeprocess is successful, you should follow the rest of the instructions in the
chapter
-
8/12/2019 Manual Tomcat
59/60
!ppendi" D. clipse Tomcat and the Tomcat Deployer @Contriuted
y (atricia arstenA
T'is solution +as contribute! by atricia %arsten. T'e actual te,t of t'e email 'as been
a!apte! for instructions.
These instructions involve the followin# componentsH
+clipse
"nt plu#in for +clipse
Tomcat /eployer
D.1. !out the Tomcat Deployer
"ccordin# to the manual that comes with the tarball, the Tomcat /eployer
-
8/12/2019 Manual Tomcat
60/60
{app.version}.war" update="true" />
&. Run antwith tar#ets allCclean compileD, distCcreate warfileD, deployCcopycontents of buildfolder to tomcatD, in this order The dist-targetmi#ht not be
necessary because the deployer seems to use the contents of the build folder as its
input, not the war file Fn the other hand, : would not )now what to provide as correctvalue for warS