old-www/HOWTO/Apache-Compile-HOWTO/tomcat.html

655 lines
12 KiB
HTML
Raw Permalink Blame History

<HTML
><HEAD
><TITLE
>Jakarta Tomcat</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Apache Compile HOWTO"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="PHP extensions"
HREF="phpext.html"><LINK
REL="NEXT"
TITLE="Further Information"
HREF="moreinfo.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Apache Compile HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="phpext.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="moreinfo.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="TOMCAT"
></A
>8. Jakarta Tomcat</H1
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN836"
></A
>8.1. What is Tomcat</H2
><A
NAME="AEN838"
></A
><TABLE
BORDER="0"
WIDTH="100%"
CELLSPACING="0"
CELLPADDING="0"
CLASS="BLOCKQUOTE"
><TR
><TD
WIDTH="10%"
VALIGN="TOP"
>&nbsp;</TD
><TD
WIDTH="80%"
VALIGN="TOP"
><P
>Tomcat is the servlet container that is used in the official Reference Implementation for the Java Servlet and JavaServer Pages technologies. The Java Servlet and JavaServer Pages specifications are developed by Sun under the Java Community Process.</P
><P
>From the authors point of view:</P
></TD
><TD
WIDTH="10%"
VALIGN="TOP"
>&nbsp;</TD
></TR
><TR
><TD
COLSPAN="2"
ALIGN="RIGHT"
VALIGN="TOP"
>--<SPAN
CLASS="ATTRIBUTION"
>jakarta.apache.org</SPAN
></TD
><TD
WIDTH="10%"
>&nbsp;</TD
></TR
></TABLE
><P
>Tomcat is the successor of jserv which is no longer developed. Tomcat supports the latest jsp and servlet-APIs
defined by sun. Unfortunately Tomcat is very difficult to build from source, because it is using its own
building-system called "ant". There is also a very long list of prerequisites if you want to build from source.
See <A
HREF="http://jakarta.apache.org/tomcat/tomcat-4.0-doc/BUILDING.txt"
TARGET="_top"
>http://jakarta.apache.org/tomcat/tomcat-4.0-doc/BUILDING.txt</A
> for more details - Good luck, and give some
feedback to the author. </P
><P
>In the meantime the HOWTO is providing some
basic support for Tomcat installed from binaries.</P
><P
>The Author is searching for some volunteers who tries to build Tomcat from source and tells what steps are required</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN846"
></A
>8.2. Prerequisites</H2
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN848"
></A
>8.2.1. Java2</H3
><DIV
CLASS="SECT4"
><H4
CLASS="SECT4"
><A
NAME="AEN850"
></A
>8.2.1.1. What is Java2</H4
><P
>Please see java.sun.com</P
><P
>Too much for this HOWTO, please see <A
HREF="http://java.sun.com/j2se/1.3/docs/relnotes/features.html"
TARGET="_top"
>http://java.sun.com/j2se/1.3/docs/relnotes/features.html</A
></P
></DIV
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN855"
></A
>8.2.2. Download the binaries</H3
><P
>Go to <A
HREF="http://java.sun.com/j2se/1.3/"
TARGET="_top"
>http://java.sun.com/j2se/1.3/</A
> <A
NAME="AEN859"
HREF="#FTN.AEN859"
><SPAN
CLASS="footnote"
>[1]</SPAN
></A
>,choose your platform and follow the steps on the site.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN861"
></A
>8.2.3. Installing the binaries</H3
><P
>Execute the binary:
<TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>chmod +x j2sdk-1_3_1_02-linux-i386.bin
./2sdk-1_3_1_02-linux-i386.bin</PRE
></FONT
></TD
></TR
></TABLE
>&#13;</P
><P
>After accepting the license, unpack the stuff and move the resulting directory to <TT
CLASS="FILENAME"
>/usr/lib</TT
>
and set an appropriate symbolic link</P
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN867"
></A
>8.3. Download the binaries</H2
><P
>Origin-Site:
<A
HREF="http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.1.18/src/jakarta-tomcat-4.1.18-src.tar.gz"
TARGET="_top"
>http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.1.18/src/jakarta-tomcat-4.1.18-src.tar.gz</A
></P
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN871"
></A
>8.3.1. Installing the binaries</H3
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>cd /usr/local
tar -xvzf jakarta-tomcat-4.1.8.tar.gz
cd jakarta-tomcat-4.1.8
cd bin
rm *.bat
echo export JAVA_HOME=/usr/lib/java/ &#62;&#62; /etc/profile
. /etc/profile</PRE
></FONT
></TD
></TR
></TABLE
><P
>To enable the Tomcat manager, you need to modify <TT
CLASS="FILENAME"
>/usr/local/jakarta-tomcat-4.1.8/conf/tomcat-users.xml</TT
>
add a user <20>admin<69> or with the role <20>manager<65>. The result should look like this:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>&#60;?xml version='1.0' encoding='utf-8'?&#62;
&#60;tomcat-users&#62;
&#60;role rolename="manager"/&#62;
&#60;role rolename="tomcat"/&#62;
&#60;role rolename="role1"/&#62;
&#60;user username="admin" password="secret" roles="manager"/&#62;
&#60;user username="tomcat" password="tomcat" roles="tomcat"/&#62;
&#60;user username="role1" password="tomcat" roles="role1"/&#62;
&#60;user username="both" password="tomcat" roles="tomcat,role1"/&#62;
&#60;/tomcat-users&#62;</PRE
></FONT
></TD
></TR
></TABLE
><P
>Now you should be able to startup tomcat:
<TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>/usr/local/apache/jakarta-tomcat-4.1.8/bin/startup.sh</PRE
></FONT
></TD
></TR
></TABLE
>&#13;</P
><P
>You should now be able to connect to: <A
HREF="http://localhost:8080/index.jsp"
TARGET="_top"
>http://localhost:8080/index.jsp</A
></P
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="MODJK"
></A
>8.4. mod_jk</H2
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN883"
></A
>8.4.1. Download the source</H3
><P
>If you like to have a native interface into your Apache Webserver, you need to build mod_jk with must be downloaded separately here:
<A
HREF="http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.1.18/src/jakarta-tomcat-connectors-4.1.18-src.tar.gz"
TARGET="_top"
>http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.1.18/src/jakarta-tomcat-connectors-4.1.18-src.tar.gz</A
>.</P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN887"
></A
>8.4.2. Building and installing</H3
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>tar -xvzf jakarta-tomcat-connectors-4.1.18-src.tar.gz
cd jakarta-tomcat-connectors-4.1.18-src/jk/native
./buildconf
./configure --with-apxs=/usr/local/apache/bin/apxs
make
make install</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN890"
></A
>8.4.3. Customizing</H3
><P
>Now follows the annoying part, the customizing of the config files. First edit
<TT
CLASS="FILENAME"
>/usr/local/jakarta-tomcat-connectors-4.1.18-src/jk/conf/workers.properties</TT
>,
and copy the file to <TT
CLASS="FILENAME"
>/usr/local/apache/conf</TT
></P
><P
>I made a sample <TT
CLASS="FILENAME"
>workers.properties</TT
> that works with the example JSPs and servlets
that comes with the Tomcat distribution. It is based on the sample workers.properties from Tomcat</P
><DIV
CLASS="EXAMPLE"
><A
NAME="AEN897"
></A
><P
><B
>Example 8. workers.properties</B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>workers.tomcat_home=/usr/local/jakarta-tomcat-4.1.18
# workers.java_home should point to your Java installation. Normally
# you should have a bin and lib directories beneath it.
#
workers.java_home=/usr/lib/java2
# You should configure your environment slash... ps=\ on NT and / on UNIX
# and maybe something different elsewhere.
#
ps=/
# The workers that your plugins should create and work with
#
worker.list=worker1
#------ DEFAULT ajp13 WORKER DEFINITION ------------------------------
#---------------------------------------------------------------------
# Defining a worker named ajp13 and of type ajp13
# Note that the name and the type do not have to match.
#
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
#------ CLASSPATH DEFINITION -----------------------------------------
#---------------------------------------------------------------------
# Additional class path components.
#
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)tomcat.jar
# The JVM that we are about to use
#
# Unix - Sun VM or blackdown
worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)lib$(ps)i386$(ps)classic$(ps)libjvm.so
# Setting the place for the stdout and stderr of tomcat
#
worker.inprocess.stdout=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stdout
worker.inprocess.stderr=$(workers.tomcat_home)$(ps)logs$(ps)inprocess.stderr</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>Next, you need to configure your apache config file <TT
CLASS="FILENAME"
>httpd.conf</TT
>.
The following example matches the examples provided by Tomcat.</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>LoadModule jk_module libexec/mod_jk.so
AddModule mod_jk.c
JkWorkersFile /usr/local/apache/conf/workers.properties
JkLogFile /var/log/httpd/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkMount /examples/servlet/* worker1
JkMount /examples/*.jsp worker1 </PRE
></FONT
></TD
></TR
></TABLE
><P
>After restarting Apache, you should now be able to connect to your JSP's via Apache. I.e:
<A
HREF="http://localhost/examples/jsp/num/numguess.jsp"
TARGET="_top"
>http://localhost/examples/jsp/num/numguess.jsp</A
></P
><P
>For the further steps like installing your servlets and jsp-files, you are responsible by yourself...</P
><DIV
CLASS="TIP"
><P
></P
><TABLE
CLASS="TIP"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="../images/tip.gif"
HSPACE="5"
ALT="Tip"></TD
><TH
ALIGN="LEFT"
VALIGN="CENTER"
><B
>Environment Variables</B
></TH
></TR
><TR
><TD
>&nbsp;</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>If Tomcat fails to start and/or your servlets could not be started the most common error made is having not
all needed classes in the <TT
CLASS="VARNAME"
>CLASSPATH</TT
> variable.</P
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
></DIV
><H3
CLASS="FOOTNOTES"
>Notes</H3
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN859"
HREF="tomcat.html#AEN859"
><SPAN
CLASS="footnote"
>[1]</SPAN
></A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>There is also version 1.4.1 of Java available, but Tomcat seems not to run with that version of Java.</P
></TD
></TR
></TABLE
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="phpext.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="moreinfo.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>PHP extensions</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Further Information</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>