tomcat 6 installation

Upload: sebeningembun

Post on 03-Jun-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Tomcat 6 Installation

    1/8

    Tomcat 6.0

    Application Developer's Guide

    InstallationInstallation

    In order to use Tomcat 6 for developing web applications, you must first install it (and thesoftware it depends on). The required steps are outlined in the following subsections.

    JDK

    Tomcat 6.0 was designed to run on !"# $.0.

    %ompatible &'s for many platforms (or lins to where they can be found) are available athttp**+ava.sun.com*+!se*.

    Tomcat

    inary downloads of the Tomcatserver are available from http**tomcat.apache.org*download-60.cgi. This manual assumes you are using the most recent release of Tomcat 6. &etailed

    instructions for downloading and installing Tomcat 6 are available here.

    In the remainder of this manual, eample shell scripts assume that you have set an environment

    variable CATALINA_HOMEthat contains the pathname to the directory in which Tomcat 6 has

    been installed. /ptionally, if Tomcat has been configured for multiple instances, each instance

    will have its own CATALINA_BASEconfigured.Ant

    inary downloads of the Antbuild tool are available from

    http**ant.apache.org*bindownload.cgi. This manual assumes you are using nt 1.2 or later. The

    instructions should also be compatible with later versions, but this has not been tested.

    &ownload and install nt from the distribution directory mentioned above. Then, add the bin

    directory of the nt distribution to your PATHenvironment variable, following the standard

    practices for your operating system platform. /nce you have done this, you will be able to

    eecute the antshell command directly.

    CVS

    esides the required tools described above, you are strongly encouraged to download and installasource code controlsystem, such as the Concurrent Version System(%3"), to maintainhistorical versions of the source files that mae up your web application. esides the server, you

    will also need appropriate client tools to chec out source code files, and chec in modifiedversions.

    http://java.sun.com/j2se/http://tomcat.apache.org/download-60.cgihttp://tomcat.apache.org/download-60.cgihttp://tomcat.apache.org/tomcat-6.0-doc/setup.htmlhttp://ant.apache.org/bindownload.cgihttp://java.sun.com/j2se/http://tomcat.apache.org/download-60.cgihttp://tomcat.apache.org/download-60.cgihttp://tomcat.apache.org/tomcat-6.0-doc/setup.htmlhttp://ant.apache.org/bindownload.cgi
  • 8/12/2019 Tomcat 6 Installation

    2/8

    &etailed instructions for installing and using source code control applications is beyond the

    scope of this manual. 4owever, %3" server and client tools for many platforms (along with

    documentation) can be downloaded from http**www.cvshome.org.

    Deployment

    Table of Contents

    Background

    Standard Directory Layout

    Shared Library Files

    Web Application Deployment Descriptor

    Tomcat Context Descriptor

    Deployment With Tomcat 6

    Background

    efore describing how to organi5e your source code directories, it is useful to eamine the

    runtime organi5ation of a web application. rior to the "ervlet I "pecification, version !.!,

    there was little consistency between server platforms. 4owever, servers that conform to the !.!(or later) specification are required to accept a Web Application Archivein a standard format,which is discussed further below.

    web application is defined as a hierarchy of directories and files in a standard layout. "uch ahierarchy can be accessed in its 7unpaced7 form, where each directory and file eists in thefilesystem separately, or in a 7paced7 form nown as a 8eb 9chive, or 89 file. The former

    format is more useful during development, while the latter is used when you distribute your

    application to be installed.

    The top-level directory of your web application hierarchy is also the document rootof yourapplication. 4ere, you will place the 4T:; files and " pages that comprise your application

  • 8/12/2019 Tomcat 6 Installation

    3/8

    this, you will end up with the following contents in your application-compatible server), the classes

    in the WEBIN!/cla""e"/directory, as well as all classes in 9 files found in the WEB

    IN!/lib/directory, are made visible to other classes within your particular web application.

    Thus, if you include all of the required library classes in one of these places (be sure to chec

    licenses for redistribution rights for any third party libraries you utili5e), you will simplify theinstallation of your web application -- no ad+ustment to the system class path (or installation ofglobal library files in your server) will be necessary.

    :uch of this information was etracted from %hapter ? of the "ervlet I "pecification, version

    !.>, which you should consult for more details.

    Shared Library iles

    ;ie most servlet containers, Tomcat 6 also supports mechanisms to install library 9 files (or

    unpaced classes) once, and mae them visible to all installed web applications (without having

    to be included inside the web application itself. The details of how Tomcat locates and shares

    such classes are described in the %lass ;oader 4/8-T/documentation. The location commonlyused within a Tomcat 6 installation for shared code is $CATALINA_HOME/li . 9 files

    placed here are visible both to web applications and internal Tomcat code. This is a good place toput &% drivers that are required for both your application or internal Tomcat use (such as for a

    &%9ealm).

    /ut of the bo, a standard Tomcat 6 installation includes a variety of pre-installed shared library

    files, including

    http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.htmlhttp://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
  • 8/12/2019 Tomcat 6 Installation

    4/8

    The Servlet 2.5andJSP 2.1A$,s that are 'undamental to &riting ser(lets and

    #a(aSer(er $ages+

    AnXML Parsercompliant &ith the #A-$ )(ersion 1+2* A$,s% so your application can

    per'orm D3"based or SA-based processing o' -"L documents+

    !eb A""lication De"loyment Descri"tor

    s mentioned above, the /WEBIN!/(eb.xmlfile contains the 8eb pplication &eployment

    &escriptor for your application. s the filename etension implies, this file is an @:;

    document, and defines everything about your application that a server needs to now (ecept the

    context path, which is assigned by the system administrator when the application is deployed).

    The complete synta and semantics for the deployment descriptor is defined in %hapter 1> of the

    "ervlet I "pecification, version !.>. /ver time, it is epected that development tools will be

    provided that create and edit the deployment descriptor for you. In the meantime, to provide astarting point, abasic web.ml fileis provided. This file includes comments that describe the

    purpose of each included element.

    NOTE- The "ervlet "pecification includes a &ocument Type &escriptor (&T&) for the webapplication deployment descriptor, and Tomcat 6 enforces the rules defined here when

    processing your application

  • 8/12/2019 Tomcat 6 Installation

    5/8

    on the subdirectory name you choose+ We &ill use this techni/ue in the b,ild.xml'ile

    that &e construct% because it is the /uickest and easiest approach during de(elopment+Be sure to restart Tomcat a'ter installing or updating your application+

    !rails an" Tomcat# Deployment Notes

    Things have been busy, and I havenCt had the time to devote to writing updates on either the

    %addy, or my wor in Drails. ut enough complaining, to pass the time until I can get some

    more quality content here, I wanted to share this little gem that too me entirely too long tofigure out.

    I wanted to be able to deploy my grails applications to a sub contet, or sub directory of the rootof my site. This way I could leave my blog at the root of my domain, and categori5e my grails

    apps a bit. Tae the following eample. "uppose I wanted to deploy a bunch of eample grailsapps in a subdirectory named EeamplesF off of the root of my web host. "omething lie

    http**GyourserverH*eamples*Gyour-app-nameH. This is how I was able to finally accomplish it.

    Deploy to a Tomcat Su%Conte&t

    If youCre a Tomcat guru this is all going to seem elementary, and it is, but it was superblydifficult for me to mine the information I needed from the web, so ICm sharing what ICve learned

    here. If, on the other hand, youCre a Tomcat newbie lie me, you hopefully have a running

    instance of the Tomcat service. If you donCt there are a number of great tutorials, including theofficial installation guide.

    :ost ofthe stuff that youCll read out there says that to deploy your grails app, you +ust upload

    your .war file to the Tomcat EwebappsF directory and youCre in business. This is true, but of

    course when you do this, you +ust end up with a =9; that loos liehttp**GyourserverHJ0J0*Gyour-app-nameH. Aow, this is fine if you only intend to deploy a few

    apps and you dont mind that application being at the root for your domain*server name. ut

    weCre trying to put our apps in a sub directory of our site, off of the root.

    :y first instinct to accomplish this was to use some of the properties of the grails app itself, and

    I found many eamples which recommended this. "o, I happily set my app.contet inapplication.properties to the path I wanted.

    m%di& $ /"&'/tomcat(eba$$"/exam$le"/M#Exam$leA$$

    This wors great when I do a grails run-app, I get the app deployed to

    http**localhostJ0J0*eamples*:y#amplepp +ust lie I wanted. ut, when I create a war and

    toss it in my Tomcat webapps directory, I still get the same old behavior of the application being

    http://tomcat.apache.org/tomcat-6.0-doc/appdev/installation.htmlhttp://tomcat.apache.org/tomcat-6.0-doc/appdev/installation.html
  • 8/12/2019 Tomcat 6 Installation

    6/8

    deployed to the root of Tomcat with the same name as the war file. "o how the hec do I deploy

    my war into a sub directory of my Tomcat siteKL

    The secret lies in not simply dumping your war file into an eisting EcontetF for Tomcat, butinstead creating your own, and pointing that contet to your war file. The first step toward this is

    to prepare a place for our webapp directories, outside of the Tomcat root webapp directory. Ichoose *srv*tomcat-webapps but youCre obviously welcome to put this anywhere you lie. "o

    letCs create the directory where weCre going to deploy our first eample app.

    m%di& $ /"&'/tomcat(eba$$"/exam$le"/M#Exam$leA$$

    Aow, we need to find the %atalina configuration directory for our Tomcat deployment. /n=buntu, which is the environment ICm using, this is at *etc*tomcat6*%atalina*localhost. 8hat

    youCll find there, are a number of @:; files each one describes a EcontetF. Mou can define

    sub-contets by using a special synta in the filename which is +ust barely mentioned in passing

    in the Tomcat docs. Mou can set a multi level contet name by using the N character. "o lets

    create a new sub-contet for our eample app at the correct path.

    cd /etc/tomcat/Catalina/localho"t

    'im exam$le"M#Exam$leA$$.xml

    Aow we need to add the content to this contet file which will tell Tomcat where to find the

    applications files. 9emember bac when we created a new directory for our tomcat webapps, thisis where weCll use it.

    exam$le"M#Exam$leA$$.xml

    )0xml 'e&"ion123.42 encoding125T!620+)context anti&e"o,&celoc%ing12*al"e2docba"e12/"&'/tomcat(eba$$"/exam$le"/M#Exam$leA$$2$ath12/exam$le"/M#Exam$leA$$2 $&i'ileged12t&,e2+

    Aow if you restart Tomcat, and un5ip your war file to *srv*tomcat-webapps*eamples*:y#amplepp you should be able to navigate to

    htt$7//)#o,&"e&'e&+76464/exam$le"/M#Exam$leA$$and see your applicationL

    How to Externalize Your Grails Coni!uration "i#e a $roessional

    Drails docs go a long way towards being the only materials you need to learn how to use Drails.=nfortunately, it can miss a few things that are common use cases.

    http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Introductionhttp://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Introduction
  • 8/12/2019 Tomcat 6 Installation

    7/8

    In any real world production app, you donCt manage your configuration from within your 89

    file. 4ow do you have a configuration file deployed out to your production server beside your

    89 fileK

    :ost of the posts out there about eternal configuration all tal about hard coding eternal

    config locations into a variable lie so

    grails+con'ig+locations 4 5 'ile789user!ome:;89app

  • 8/12/2019 Tomcat 6 Installation

    8/8

    The ey points in this method that are not in the docs or blogs to come before me

    ,t actually &orks+ ,t appears some de(s don>t bother testing their methods be'ore posting

    the code+ ?ou ha(e to initiali.e the grails+con'ig+location as a list i' it isn>t already+ And itis grails+con'ig+location+ t setup

    yet so println it &as+ ,>m sure &ith some 'iddling those could be replaced &ith log

    statements+

    ,' , sound harsh% it>s because ,>(e ust dealt &ith another stupid rails issue that should

    be a no brainer+ And i' not in the o''icial documentation% the or E blog posts and aStack 3(er'lo& /uestion about this should ha(e pro(ided the C300@CT FCG,