| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 1 | <html><head><META http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Application Developer's Guide (7.0.77) - Development Processes</title><meta name="author" content="Craig R. McClanahan"><style type="text/css" media="print">
 | 
 | 2 |     .noPrint {display: none;}
 | 
 | 3 |     td#mainBody {width: 100%;}
 | 
 | 4 | </style><style type="text/css">
 | 
 | 5 | code {background-color:rgb(224,255,255);padding:0 0.1em;}
 | 
 | 6 | code.attributeName, code.propertyName {background-color:transparent;}
 | 
 | 7 | 
 | 
 | 8 | 
 | 
 | 9 | table {
 | 
 | 10 |   border-collapse: collapse;
 | 
 | 11 |   text-align: left;
 | 
 | 12 | }
 | 
 | 13 | table *:not(table) {
 | 
 | 14 |   /* Prevent border-collapsing for table child elements like <div> */
 | 
 | 15 |   border-collapse: separate;
 | 
 | 16 | }
 | 
 | 17 | 
 | 
 | 18 | th {
 | 
 | 19 |   text-align: left;
 | 
 | 20 | }
 | 
 | 21 | 
 | 
 | 22 | 
 | 
 | 23 | div.codeBox pre code, code.attributeName, code.propertyName, code.noHighlight, .noHighlight code {
 | 
 | 24 |   background-color: transparent;
 | 
 | 25 | }
 | 
 | 26 | div.codeBox {
 | 
 | 27 |   overflow: auto;
 | 
 | 28 |   margin: 1em 0;
 | 
 | 29 | }
 | 
 | 30 | div.codeBox pre {
 | 
 | 31 |   margin: 0;
 | 
 | 32 |   padding: 4px;
 | 
 | 33 |   border: 1px solid #999;
 | 
 | 34 |   border-radius: 5px;
 | 
 | 35 |   background-color: #eff8ff;
 | 
 | 36 |   display: table; /* To prevent <pre>s from taking the complete available width. */
 | 
 | 37 |   /*
 | 
 | 38 |   When it is officially supported, use the following CSS instead of display: table
 | 
 | 39 |   to prevent big <pre>s from exceeding the browser window:
 | 
 | 40 |   max-width: available;
 | 
 | 41 |   width: min-content;
 | 
 | 42 |   */
 | 
 | 43 | }
 | 
 | 44 | 
 | 
 | 45 | div.codeBox pre.wrap {
 | 
 | 46 |   white-space: pre-wrap;
 | 
 | 47 | }
 | 
 | 48 | 
 | 
 | 49 | 
 | 
 | 50 | table.defaultTable tr, table.detail-table tr {
 | 
 | 51 |     border: 1px solid #CCC;
 | 
 | 52 | }
 | 
 | 53 | 
 | 
 | 54 | table.defaultTable tr:nth-child(even), table.detail-table tr:nth-child(even) {
 | 
 | 55 |     background-color: #FAFBFF;
 | 
 | 56 | }
 | 
 | 57 | 
 | 
 | 58 | table.defaultTable tr:nth-child(odd), table.detail-table tr:nth-child(odd) {
 | 
 | 59 |     background-color: #EEEFFF;
 | 
 | 60 | }
 | 
 | 61 | 
 | 
 | 62 | table.defaultTable th, table.detail-table th {
 | 
 | 63 |   background-color: #88b;
 | 
 | 64 |   color: #fff;
 | 
 | 65 | }
 | 
 | 66 | 
 | 
 | 67 | table.defaultTable th, table.defaultTable td, table.detail-table th, table.detail-table td {
 | 
 | 68 |   padding: 5px 8px;
 | 
 | 69 | }
 | 
 | 70 | 
 | 
 | 71 | 
 | 
 | 72 | p.notice {
 | 
 | 73 |     border: 1px solid rgb(255, 0, 0);
 | 
 | 74 |     background-color: rgb(238, 238, 238);
 | 
 | 75 |     color: rgb(0, 51, 102);
 | 
 | 76 |     padding: 0.5em;
 | 
 | 77 |     margin: 1em 2em 1em 1em;
 | 
 | 78 | }
 | 
 | 79 | </style></head><body bgcolor="#ffffff" text="#000000" link="#525D76" alink="#525D76" vlink="#525D76"><table border="0" width="100%" cellspacing="0"><!--PAGE HEADER--><tr><td><!--PROJECT LOGO--><a href="http://tomcat.apache.org/"><img src="../images/tomcat.gif" align="right" alt="
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 80 |       The Apache Tomcat Servlet/JSP Container
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 81 |     " border="0"></a></td><td><h1><font face="arial,helvetica,sanserif">Apache Tomcat 7</font></h1><font face="arial,helvetica,sanserif">Version 7.0.77, Mar 28 2017</font></td><td><!--APACHE LOGO--><a href="http://www.apache.org/"><img src="../images/asf-logo.svg" align="right" alt="Apache Logo" border="0" style="width: 266px;height: 83px;"></a></td></tr></table><table border="0" width="100%" cellspacing="4"><!--HEADER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><tr><!--LEFT SIDE NAVIGATION--><td width="20%" valign="top" nowrap class="noPrint"><p><strong>Links</strong></p><ul><li><a href="../index.html">Docs Home</a></li><li><a href="index.html">App Dev Guide Home</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li><li><a href="#comments_section">User Comments</a></li></ul><p><strong>Contents</strong></p><ul><li><a href="index.html">Contents</a></li><li><a href="introduction.html">Introduction</a></li><li><a href="installation.html">Installation</a></li><li><a href="deployment.html">Deployment</a></li><li><a href="source.html">Source Code</a></li><li><a href="processes.html">Processes</a></li><li><a href="sample/">Example App</a></li></ul></td><!--RIGHT SIDE MAIN BODY--><td width="80%" valign="top" align="left" id="mainBody"><h1>Development Processes</h1><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Table of Contents"><!--()--></a><a name="Table_of_Contents"><strong>Table of Contents</strong></a></font></td></tr><tr><td><blockquote>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 82 | <ul><li><a href="#Development_Processes">Development Processes</a><ol><li><a href="#One-Time_Setup_of_Ant_and_Tomcat_for_Development">One-Time Setup of Ant and Tomcat for Development</a></li><li><a href="#Create_Project_Source_Code_Directory">Create Project Source Code Directory</a></li><li><a href="#Edit_Source_Code_and_Pages">Edit Source Code and Pages</a></li><li><a href="#Build_the_Web_Application">Build the Web Application</a></li><li><a href="#Test_Your_Web_Application">Test Your Web Application</a></li><li><a href="#Creating_a_Release">Creating a Release</a></li></ol></li></ul>
 | 
 | 83 | </blockquote></td></tr></table><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Development Processes"><!--()--></a><a name="Development_Processes"><strong>Development Processes</strong></a></font></td></tr><tr><td><blockquote>
 | 
 | 84 | 
 | 
 | 85 | <p>Although application development can take many forms, this manual proposes
 | 
 | 86 | a fairly generic process for creating web applications using Tomcat.  The
 | 
 | 87 | following sections highlight the commands and tasks that you, as the developer
 | 
 | 88 | of the code, will perform.  The same basic approach works when you have
 | 
 | 89 | multiple programmers involved, as long as you have an appropriate source code
 | 
 | 90 | control system and internal team rules about who is working on what parts
 | 
 | 91 | of the application at any given time.</p>
 | 
 | 92 | 
 | 
 | 93 | <p>The task descriptions below assume that you will be using CVS for source
 | 
 | 94 | code control, and that you have already configured access to the appropriate
 | 
 | 95 | CVS repository.  Instructions for doing this are beyond the scope of this
 | 
 | 96 | manual.  If you are using a different source code control environment, you
 | 
 | 97 | will need to figure out the corresponding commands for your system.</p>
 | 
 | 98 | 
 | 
 | 99 | 
 | 
 | 100 | <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="One-Time Setup of Ant and Tomcat for Development"><!--()--></a><a name="One-Time_Setup_of_Ant_and_Tomcat_for_Development"><strong>One-Time Setup of Ant and Tomcat for Development</strong></a></font></td></tr><tr><td><blockquote>
 | 
 | 101 | 
 | 
 | 102 | <p>In order to take advantage of the special Ant tasks that interact with the
 | 
 | 103 | <em>Manager</em> web application, you need to perform the following tasks
 | 
 | 104 | once (no matter how many web applications you plan to develop).</p>
 | 
 | 105 | <ul>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 106 | <li><p><em>Configure the Ant custom tasks</em>.  The implementation code for the
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 107 |     Ant custom tasks is in a JAR file named
 | 
 | 108 |     <code>$CATALINA_HOME/lib/catalina-ant.jar</code>, which must be
 | 
 | 109 |     copied in to the <code>lib</code> directory of your Ant installation.
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 110 |     </p></li>
 | 
 | 111 | <li><p><em>Define one or more Tomcat users</em>.  The <em>Manager</em> web
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 112 |     application runs under a security constraint that requires a user to be
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 113 |     logged in, and have the security role <code>manager-script</code> assigned
 | 
 | 114 |     to him or her.  How such users are defined depends on which Realm you have
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 115 |     configured in Tomcat's <code>conf/server.xml</code> file -- see the
 | 
 | 116 |     <a href="../realm-howto.html">Realm Configuration HOW-TO</a> for more
 | 
 | 117 |     information.  You may define any number of users (with any username
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 118 |     and password that you like) with the <code>manager-script</code> role.
 | 
 | 119 |     </p></li>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 120 | </ul>
 | 
 | 121 | 
 | 
 | 122 | </blockquote></td></tr></table>
 | 
 | 123 | 
 | 
 | 124 | 
 | 
 | 125 | <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Create Project Source Code Directory"><!--()--></a><a name="Create_Project_Source_Code_Directory"><strong>Create Project Source Code Directory</strong></a></font></td></tr><tr><td><blockquote>
 | 
 | 126 | 
 | 
 | 127 | <p>The first step is to create a new project source directory, and customize
 | 
 | 128 | the <code>build.xml</code> and <code>build.properties</code> files you will
 | 
 | 129 | be using.  The directory structure is described in <a href="source.html">the
 | 
 | 130 | previous section</a>, or you can use the
 | 
 | 131 | <a href="sample/">sample application</a> as a starting point.</p>
 | 
 | 132 | 
 | 
 | 133 | <p>Create your project source directory, and define it within your CVS
 | 
 | 134 | repository.  This might be done by a series of commands like this, where
 | 
 | 135 | <code>{project}</code> is the name under which your project should be
 | 
 | 136 | stored in the CVS repository, and {username} is your login username:</p>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 137 | <div class="codeBox"><pre><code>cd {my home directory}
 | 
 | 138 | mkdir myapp <-- Assumed "project source directory"
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 139 | cd myapp
 | 
 | 140 | mkdir docs
 | 
 | 141 | mkdir src
 | 
 | 142 | mkdir web
 | 
 | 143 | mkdir web/WEB-INF
 | 
 | 144 | cvs import -m "Initial Project Creation" {project} \
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 145 |     {username} start</code></pre></div>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 146 | 
 | 
 | 147 | <p>Now, to verify that it was created correctly in CVS, we will perform a
 | 
 | 148 | checkout of the new project:</p>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 149 | <div class="codeBox"><pre><code>cd ..
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 150 | mv myapp myapp.bu
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 151 | cvs checkout {project}</code></pre></div>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 152 | 
 | 
 | 153 | <p>Next, you will need to create and check in an initial version of the
 | 
 | 154 | <code>build.xml</code> script to be used for development.  For getting
 | 
 | 155 | started quickly and easily, base your <code>build.xml</code> on the
 | 
 | 156 | <a href="build.xml.txt">basic build.xml file</a>, included with this manual,
 | 
 | 157 | or code it from scratch.</p>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 158 | <div class="codeBox"><pre><code>cd {my home directory}
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 159 | cd myapp
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 160 | emacs build.xml     <-- if you want a real editor :-)
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 161 | cvs add build.xml
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 162 | cvs commit</code></pre></div>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 163 | 
 | 
 | 164 | <p>Until you perform the CVS commit, your changes are local to your own
 | 
 | 165 | development directory.  Committing makes those changes visible to other
 | 
 | 166 | developers on your team that are sharing the same CVS repository.</p>
 | 
 | 167 | 
 | 
 | 168 | <p>The next step is to customize the Ant <em>properties</em> that are
 | 
 | 169 | named in the <code>build.xml</code> script.  This is done by creating a
 | 
 | 170 | file named <code>build.properties</code> in your project's top-level
 | 
 | 171 | directory.  The supported properties are listed in the comments inside
 | 
 | 172 | the sample <code>build.xml</code> script.  At a minimum, you will generally
 | 
 | 173 | need to define the <code>catalina.home</code> property defining where
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 174 | Tomcat is installed, and the manager application username and password.
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 175 | You might end up with something like this:</p>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 176 | <div class="codeBox"><pre><code># Context path to install this application on
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 177 | app.path=/hello
 | 
 | 178 | 
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 179 | # Tomcat 7 installation directory
 | 
 | 180 | catalina.home=/usr/local/apache-tomcat-7.0
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 181 | 
 | 
 | 182 | # Manager webapp username and password
 | 
 | 183 | manager.username=myusername
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 184 | manager.password=mypassword</code></pre></div>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 185 | 
 | 
 | 186 | <p>In general, you will <strong>not</strong> want to check the
 | 
 | 187 | <code>build.properties</code> file in to the CVS repository, because it
 | 
 | 188 | is unique to each developer's environment.</p>
 | 
 | 189 | 
 | 
 | 190 | <p>Now, create the initial version of the web application deployment
 | 
 | 191 | descriptor.  You can base <code>web.xml</code> on the
 | 
 | 192 | <a href="web.xml.txt">basic web.xml file</a>, or code it from scratch.</p>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 193 | <div class="codeBox"><pre><code>cd {my home directory}
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 194 | cd myapp/web/WEB-INF
 | 
 | 195 | emacs web.xml
 | 
 | 196 | cvs add web.xml
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 197 | cvs commit</code></pre></div>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 198 | 
 | 
 | 199 | Note that this is only an example web.xml file.  The full definition
 | 
 | 200 | of the deployment descriptor file is in the
 | 
 | 201 | <a href="http://wiki.apache.org/tomcat/Specifications">Servlet Specification.</a>
 | 
 | 202 | 
 | 
 | 203 | </blockquote></td></tr></table>
 | 
 | 204 | 
 | 
 | 205 | 
 | 
 | 206 | <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Edit Source Code and Pages"><!--()--></a><a name="Edit_Source_Code_and_Pages"><strong>Edit Source Code and Pages</strong></a></font></td></tr><tr><td><blockquote>
 | 
 | 207 | 
 | 
 | 208 | <p>The edit/build/test tasks will generally be your most common activities
 | 
 | 209 | during development and maintenance.  The following general principles apply.
 | 
 | 210 | As described in <a href="source.html">Source Organization</a>, newly created
 | 
 | 211 | source files should be located in the appropriate subdirectory, under your
 | 
 | 212 | project source directory.</p>
 | 
 | 213 | 
 | 
 | 214 | <p>Whenever you wish to refresh your development directory to reflect the
 | 
 | 215 | work performed by other developers, you will ask CVS to do it for you:</p>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 216 | <div class="codeBox"><pre><code>cd {my home directory}
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 217 | cd myapp
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 218 | cvs update -dP</code></pre></div>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 219 | 
 | 
 | 220 | <p>To create a new file, go to the appropriate directory, create the file,
 | 
 | 221 | and register it with CVS.  When you are satisfied with it's contents (after
 | 
 | 222 | building and testing is successful), commit the new file to the repository.
 | 
 | 223 | For example, to create a new JSP page:</p>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 224 | <div class="codeBox"><pre><code>cd {my home directory}
 | 
 | 225 | cd myapp/web        <-- Ultimate destination is document root
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 226 | emacs mypage.jsp
 | 
 | 227 | cvs add mypage.jsp
 | 
 | 228 | ... build and test the application ...
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 229 | cvs commit</code></pre></div>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 230 | 
 | 
 | 231 | <p>Java source code that is defined in packages must be organized in a
 | 
 | 232 | directory hierarchy (under the <strong>src/</strong> subdirectory) that
 | 
 | 233 | matches the package names.  For example, a Java class named
 | 
 | 234 | <code>com.mycompany.mypackage.MyClass.java</code> should be stored in file
 | 
 | 235 | <code>src/com/mycompany/mypackage/MyClass.java</code>.
 | 
 | 236 | Whenever you create a new subdirectory, don't forget to
 | 
 | 237 | register it with CVS.</p>
 | 
 | 238 | 
 | 
 | 239 | <p>To edit an existing source file, you will generally just start editing
 | 
 | 240 | and testing, then commit the changed file when everything works.  Although
 | 
 | 241 | CVS can be configured to required you to "check out" or "lock" a file you
 | 
 | 242 | are going to be modifying, this is generally not used.</p>
 | 
 | 243 | 
 | 
 | 244 | </blockquote></td></tr></table>
 | 
 | 245 | 
 | 
 | 246 | 
 | 
 | 247 | <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Build the Web Application"><!--()--></a><a name="Build_the_Web_Application"><strong>Build the Web Application</strong></a></font></td></tr><tr><td><blockquote>
 | 
 | 248 | 
 | 
 | 249 | <p>When you are ready to compile the application, issue the following
 | 
 | 250 | commands (generally, you will want a shell window open that is set to
 | 
 | 251 | the project source directory, so that only the last command is needed):</p>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 252 | <div class="codeBox"><pre><code>cd {my home directory}
 | 
 | 253 | cd myapp        <-- Normally leave a window open here
 | 
 | 254 | ant</code></pre></div>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 255 | 
 | 
 | 256 | <p>The Ant tool will be execute the default "compile" target in your
 | 
 | 257 | <code>build.xml</code> file, which will compile any new or updated Java
 | 
 | 258 | code.  If this is the first time you compile after a "build clean",
 | 
 | 259 | it will cause everything to be recompiled.</p>
 | 
 | 260 | 
 | 
 | 261 | <p>To force the recompilation of your entire application, do this instead:</p>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 262 | <div class="codeBox"><pre><code>cd {my home directory}
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 263 | cd myapp
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 264 | ant all</code></pre></div>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 265 | 
 | 
 | 266 | <p>This is a very good habit immediately before checking in changes, to
 | 
 | 267 | make sure that you have not introduced any subtle problems that Javac's
 | 
 | 268 | conditional checking did not catch.</p>
 | 
 | 269 | 
 | 
 | 270 | </blockquote></td></tr></table>
 | 
 | 271 | 
 | 
 | 272 | 
 | 
 | 273 | <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Test Your Web Application"><!--()--></a><a name="Test_Your_Web_Application"><strong>Test Your Web Application</strong></a></font></td></tr><tr><td><blockquote>
 | 
 | 274 | 
 | 
 | 275 | <p>To test your application, you will want to install it under Tomcat.  The
 | 
 | 276 | quickest way to do that is to use the custom Ant tasks that are included in
 | 
 | 277 | the sample <code>build.xml</code> script.  Using these commands might follow
 | 
 | 278 | a pattern like this:</p>
 | 
 | 279 | <ul>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 280 | <li><p><em>Start Tomcat if needed</em>.  If Tomcat is not already running,
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 281 |     you will need to start it in the usual way.
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 282 |     </p></li>
 | 
 | 283 | <li><p><em>Compile your application</em>.  Use the <code>ant compile</code>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 284 |     command (or just <code>ant</code>, since this is the default).  Make
 | 
 | 285 |     sure that there are no compilation errors.
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 286 |     </p></li>
 | 
 | 287 | <li><p><em>Install the application</em>.  Use the <code>ant install</code>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 288 |     command.  This tells Tomcat to immediately start running your app on
 | 
 | 289 |     the context path defined in the <code>app.path</code> build property.
 | 
 | 290 |     Tomcat does <strong>NOT</strong> have to be restarted for this to
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 291 |     take effect.
 | 
 | 292 |     </p></li>
 | 
 | 293 | <li><p><em>Test the application</em>.  Using your browser or other testing
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 294 |     tools, test the functionality of your application.
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 295 |     </p></li>
 | 
 | 296 | <li><p><em>Modify and rebuild as needed</em>.  As you discover that changes
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 297 |     are required, make those changes in the original <strong>source</strong>
 | 
 | 298 |     files, not in the output build directory, and re-issue the
 | 
 | 299 |     <code>ant compile</code> command.  This ensures that your changes will
 | 
 | 300 |     be available to be saved (via <code>cvs commit</code>) later on --
 | 
 | 301 |     the output build directory is deleted and recreated as necessary.
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 302 |     </p></li>
 | 
 | 303 | <li><p><em>Reload the application</em>.  Tomcat will recognize changes in
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 304 |     JSP pages automatically, but it will continue to use the old versions
 | 
 | 305 |     of any servlet or JavaBean classes until the application is reloaded.
 | 
 | 306 |     You can trigger this by executing the <code>ant reload</code> command.
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 307 |     </p></li>
 | 
 | 308 | <li><p><em>Remove the application when you are done</em>.  When you are through
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 309 |     working on this application, you can remove it from live execution by
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 310 |     running the <code>ant remove</code> command.
 | 
 | 311 |     </p></li>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 312 | </ul>
 | 
 | 313 | 
 | 
 | 314 | <p>Do not forget to commit your changes to the source code repository when
 | 
 | 315 | you have completed your testing!</p>
 | 
 | 316 | 
 | 
 | 317 | </blockquote></td></tr></table>
 | 
 | 318 | 
 | 
 | 319 | 
 | 
 | 320 | <table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#828DA6"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="Creating a Release"><!--()--></a><a name="Creating_a_Release"><strong>Creating a Release</strong></a></font></td></tr><tr><td><blockquote>
 | 
 | 321 | 
 | 
 | 322 | <p>When you are through adding new functionality, and you've tested everything
 | 
 | 323 | (you DO test, don't you :-), it is time to create the distributable version
 | 
 | 324 | of your web application that can be deployed on the production server.  The
 | 
 | 325 | following general steps are required:</p>
 | 
 | 326 | <ul>
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 327 | <li><p>Issue the command <code>ant all</code> from the project source
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 328 |     directory, to rebuild everything from scratch one last time.
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 329 |     </p></li>
 | 
 | 330 | <li><p>Use the <code>cvs tag</code> command to create an identifier for
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 331 |     all of the source files utilized to create this release.  This allows
 | 
 | 332 |     you to reliably reconstruct a release (from sources) at a later
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 333 |     time.
 | 
 | 334 |     </p></li>
 | 
 | 335 | <li><p>Issue the command <code>ant dist</code> to create a distributable
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 336 |     web application archive (WAR) file, as well as a JAR file containing
 | 
 | 337 |     the corresponding source code.
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 338 |     </p></li>
 | 
 | 339 | <li><p>Package the contents of the <code>dist</code> directory using the
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 340 |     <strong>tar</strong> or <strong>zip</strong> utility, according to
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 341 |     the standard release procedures used by your organization.
 | 
 | 342 |     </p></li>
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 343 | </ul>
 | 
 | 344 | 
 | 
 | 345 | </blockquote></td></tr></table>
 | 
 | 346 | 
 | 
 | 347 | 
 | 
| 刘洪青 | 6266f99 | 2017-05-15 21:21:03 +0800 | [diff] [blame^] | 348 | </blockquote></td></tr></table></td></tr><tr class="noPrint"><td width="20%" valign="top" nowrap class="noPrint"></td><td width="80%" valign="top" align="left"><table border="0" cellspacing="0" cellpadding="2"><tr><td bgcolor="#525D76"><font color="#ffffff" face="arial,helvetica.sanserif"><a name="comments_section" id="comments_section"><strong>Comments</strong></a></font></td></tr><tr><td><blockquote><p class="notice"><strong>Notice: </strong>This comments section collects your suggestions
 | 
 | 349 |               on improving documentation for Apache Tomcat.<br><br>
 | 
 | 350 |               If you have trouble and need help, read
 | 
 | 351 |               <a href="http://tomcat.apache.org/findhelp.html">Find Help</a> page
 | 
 | 352 |               and ask your question on the tomcat-users
 | 
 | 353 |               <a href="http://tomcat.apache.org/lists.html">mailing list</a>.
 | 
 | 354 |               Do not ask such questions here. This is not a Q&A section.<br><br>
 | 
 | 355 |               The Apache Comments System is explained <a href="../comments.html">here</a>.
 | 
 | 356 |               Comments may be removed by our moderators if they are either
 | 
 | 357 |               implemented or considered invalid/off-topic.</p><script type="text/javascript"><!--//--><![CDATA[//><!--
 | 
 | 358 |               var comments_shortname = 'tomcat';
 | 
 | 359 |               var comments_identifier = 'http://tomcat.apache.org/tomcat-7.0-doc/appdev/processes.html';
 | 
 | 360 |               (function(w, d) {
 | 
 | 361 |                   if (w.location.hostname.toLowerCase() == "tomcat.apache.org") {
 | 
 | 362 |                       d.write('<div id="comments_thread"><\/div>');
 | 
 | 363 |                       var s = d.createElement('script');
 | 
 | 364 |                       s.type = 'text/javascript';
 | 
 | 365 |                       s.async = true;
 | 
 | 366 |                       s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
 | 
 | 367 |                       (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
 | 
 | 368 |                   }
 | 
 | 369 |                   else {
 | 
 | 370 |                       d.write('<div id="comments_thread"><strong>Comments are disabled for this page at the moment.<\/strong><\/div>');
 | 
 | 371 |                   }
 | 
 | 372 |               })(window, document);
 | 
 | 373 |               //--><!]]></script></blockquote></td></tr></table></td></tr><!--FOOTER SEPARATOR--><tr><td colspan="2"><hr noshade size="1"></td></tr><!--PAGE FOOTER--><tr><td colspan="2"><div align="center"><font color="#525D76" size="-1"><em>
 | 
 | 374 |         Copyright © 1999-2017, Apache Software Foundation
 | 
| Hongqing Liu | fd5ee81 | 2014-05-10 16:32:51 +0800 | [diff] [blame] | 375 |         </em></font></div></td></tr></table></body></html> |