Cheng Tang | 07b3087 | 2014-04-27 16:37:18 +0800 | [diff] [blame^] | 1 | ================================================================================
|
| 2 | Licensed to the Apache Software Foundation (ASF) under one or more
|
| 3 | contributor license agreements. See the NOTICE file distributed with
|
| 4 | this work for additional information regarding copyright ownership.
|
| 5 | The ASF licenses this file to You under the Apache License, Version 2.0
|
| 6 | (the "License"); you may not use this file except in compliance with
|
| 7 | the License. You may obtain a copy of the License at
|
| 8 |
|
| 9 | http://www.apache.org/licenses/LICENSE-2.0
|
| 10 |
|
| 11 | Unless required by applicable law or agreed to in writing, software
|
| 12 | distributed under the License is distributed on an "AS IS" BASIS,
|
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 14 | See the License for the specific language governing permissions and
|
| 15 | limitations under the License.
|
| 16 | ================================================================================
|
| 17 |
|
| 18 | $Id: BUILDING.txt 1457383 2013-03-17 06:22:36Z kkolinko $
|
| 19 |
|
| 20 | ====================================================
|
| 21 | Building The Apache Tomcat 7.0 Servlet/JSP Container
|
| 22 | ====================================================
|
| 23 |
|
| 24 | This subproject contains the source code for Tomcat 7.0, a container that
|
| 25 | implements the Servlet 3.0 and JSP 2.2 specifications from the Java
|
| 26 | Community Process <http://www.jcp.org/>.
|
| 27 |
|
| 28 | Note: If you just need to run Apache Tomcat, it is not necessary to build
|
| 29 | it. You may simply download a binary distribution. It is cross-platform.
|
| 30 | Read RUNNING.txt for the instruction on how to run it.
|
| 31 |
|
| 32 | In order to build a binary distribution version of Apache Tomcat from a
|
| 33 | source distribution, do the following:
|
| 34 |
|
| 35 |
|
| 36 | (1) Download and Install a Java Development Kit
|
| 37 |
|
| 38 | 1. If the JDK is already installed, skip to (2).
|
| 39 |
|
| 40 | 2. Download a version 6 of Java Development Kit (JDK) release (use the
|
| 41 | latest update available for your chosen version) from
|
| 42 |
|
| 43 | http://www.oracle.com/technetwork/java/javase/downloads/index.html
|
| 44 | or from another JDK vendor.
|
| 45 |
|
| 46 | Note regarding later versions of Java:
|
| 47 |
|
| 48 | As documented elsewhere, one of components in Apache Tomcat includes
|
| 49 | a private copy of the Apache Commons DBCP library. The source code
|
| 50 | for this library is downloaded, processed by the build script
|
| 51 | (renaming the packages) and compiled.
|
| 52 |
|
| 53 | Due to changes in JDBC interfaces implemented by the library between
|
| 54 | versions of Java SE specification, the library has to target specific
|
| 55 | version of Java and can be compiled only with the JDK version
|
| 56 | implementing this version of specification.
|
| 57 |
|
| 58 | See Apache Commons DBCP project web site for more details on
|
| 59 | available versions of the library and its requirements,
|
| 60 |
|
| 61 | http://commons.apache.org/dbcp/
|
| 62 |
|
| 63 | If you really want to use a later version of JDK to build Tomcat,
|
| 64 | several workarounds are possible. One of them is to skip building
|
| 65 | the component (tomcat-dbcp.jar).
|
| 66 |
|
| 67 | 3. Install the JDK according to the instructions included with the release.
|
| 68 |
|
| 69 | 4. Set an environment variable JAVA_HOME to the pathname of the directory
|
| 70 | into which you installed the JDK release.
|
| 71 |
|
| 72 |
|
| 73 | (2) Install Apache Ant 1.8.x on your computer
|
| 74 |
|
| 75 | 1. If Apache Ant 1.8.x is already installed on your computer, skip to (3).
|
| 76 |
|
| 77 | 2. Download a binary distribution of Ant 1.8.x from:
|
| 78 |
|
| 79 | http://ant.apache.org/bindownload.cgi
|
| 80 |
|
| 81 | 3. Unpack the binary distribution into a convenient location so that the
|
| 82 | Ant release resides in its own directory (conventionally named
|
| 83 | "apache-ant-[version]").
|
| 84 |
|
| 85 | For the purposes of the remainder of this document, the symbolic name
|
| 86 | "${ant.home}" is used to refer to the full pathname of the release
|
| 87 | directory.
|
| 88 |
|
| 89 | 4. Create an ANT_HOME environment variable to point the directory
|
| 90 | ${ant.home}.
|
| 91 |
|
| 92 | 5. Modify the PATH environment variable to include the directory
|
| 93 | ${ant.home}/bin in its list. This makes the "ant" command line script
|
| 94 | available, which will be used to actually perform the build.
|
| 95 |
|
| 96 |
|
| 97 | (3) Building Tomcat 7.0
|
| 98 |
|
| 99 | (3.1) Checkout or obtain the source code for Tomcat 7.0
|
| 100 |
|
| 101 | Checkout the source using SVN, selecting a tag for released version or
|
| 102 | trunk for the current development code, or download and unpack a source
|
| 103 | package.
|
| 104 |
|
| 105 | * Tomcat SVN repository URL:
|
| 106 |
|
| 107 | http://svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk/
|
| 108 |
|
| 109 | * Source packages can be downloaded from:
|
| 110 |
|
| 111 | http://tomcat.apache.org/download-70.cgi
|
| 112 |
|
| 113 | The location where the source has been placed will be further referred as
|
| 114 | ${tomcat.source}.
|
| 115 |
|
| 116 | (3.2) Building
|
| 117 |
|
| 118 | 1. The build is controlled by creating a ${tomcat.source}/build.properties
|
| 119 | file.
|
| 120 |
|
| 121 | It is recommended to always create the file, because of unfortunate
|
| 122 | default value of base.path property. You may start with the following
|
| 123 | content for the file:
|
| 124 |
|
| 125 | # ----- Default Base Path for Dependent Packages -----
|
| 126 | # Replace this path with the directory path where dependencies binaries
|
| 127 | # should be downloaded
|
| 128 | base.path=/home/me/some-place-to-download-to
|
| 129 |
|
| 130 | 2. Configure base.path property by adding it to the
|
| 131 | ${tomcat.source}/build.properties file.
|
| 132 |
|
| 133 | The base.path property specifies the place where Tomcat dependencies
|
| 134 | required by the build are downloaded. It is recommended to place this
|
| 135 | directory outside of the source tree, so that you do not waste your
|
| 136 | time re-downloading the libraries.
|
| 137 |
|
| 138 | * WARNING: The default value of base.path property makes the build script
|
| 139 | to download libraries required to build Tomcat to the /usr/share/java
|
| 140 | directory. On a typical Linux or MacOX system an ordinary user will not
|
| 141 | have access to write to this directory. Even if you do have access to
|
| 142 | that directory, it is likely not appropriate for you to write there.
|
| 143 |
|
| 144 | On Windows this usually corresponds to the "C:\usr\share\java"
|
| 145 | directory, unless Cygwin is used.
|
| 146 |
|
| 147 | * NOTE: Users accessing the Internet through a proxy must use the properties
|
| 148 | file to indicate to Ant the proxy configuration.
|
| 149 |
|
| 150 | The following properties should be added to the ${tomcat.source}/build.properties
|
| 151 | file.
|
| 152 |
|
| 153 | proxy.use=on
|
| 154 | proxy.host=proxy.domain
|
| 155 | proxy.port=8080
|
| 156 | proxy.user=username
|
| 157 | proxy.password=password
|
| 158 |
|
| 159 | See Apache Ant documentation for the <setproxy> task for details.
|
| 160 |
|
| 161 | 3. Go to the sources directory and run Ant:
|
| 162 |
|
| 163 | cd ${tomcat.source}
|
| 164 | ant
|
| 165 |
|
| 166 | This will execute the "deploy" target in build.xml.
|
| 167 |
|
| 168 | Once the build has completed successfully, a usable Tomcat installation
|
| 169 | will have been produced in the ${tomcat.source}/output/build directory,
|
| 170 | and can be started and stopped with the usual scripts.
|
| 171 |
|
| 172 | Note that the build includes Tomcat documentation, which can be found
|
| 173 | in the output/build/webapps/docs directory.
|
| 174 |
|
| 175 | The path of the output directory can be controlled by specifying the
|
| 176 | "tomcat.output" property in the build.properties file.
|
| 177 |
|
| 178 | * NOTE: Do not run the build as the root user. Building and running Tomcat
|
| 179 | does not require root privileges.
|
| 180 |
|
| 181 |
|
| 182 | (4) Updating sources and rebuilding
|
| 183 |
|
| 184 | It is recommended that you regularly update the downloaded Tomcat 7.0
|
| 185 | sources using your SVN client.
|
| 186 |
|
| 187 | For a quick rebuild of only modified code you can use:
|
| 188 |
|
| 189 | cd ${tomcat.source}
|
| 190 | ant
|
| 191 |
|
| 192 |
|
| 193 | (5) Special builds
|
| 194 |
|
| 195 | There are several targets in Tomcat build files that are useful to be
|
| 196 | called separately. They build components that you may want to build
|
| 197 | quickly, or ones that are included in the full release and are not built
|
| 198 | during the default "deploy" build.
|
| 199 |
|
| 200 | (5.1) Building documentation
|
| 201 |
|
| 202 | The documentation web application is built during the default "deploy"
|
| 203 | build.
|
| 204 |
|
| 205 | It can be built quickly by using the following commands:
|
| 206 |
|
| 207 | cd ${tomcat.source}
|
| 208 | ant build-docs
|
| 209 |
|
| 210 | The output of this command will be found in the following directory:
|
| 211 |
|
| 212 | output/build/webapps/docs
|
| 213 |
|
| 214 |
|
| 215 | The API documentation (Javadoc) is built during a "release" build. It is
|
| 216 | easy to build it separately by using the following commands:
|
| 217 |
|
| 218 | cd ${tomcat.source}
|
| 219 | ant javadoc
|
| 220 |
|
| 221 | The output of this command will be found in the following directories:
|
| 222 |
|
| 223 | output/dist/webapps/docs/api
|
| 224 | output/dist/webapps/docs/elapi
|
| 225 | output/dist/webapps/docs/jspapi
|
| 226 | output/dist/webapps/docs/servletapi
|
| 227 |
|
| 228 |
|
| 229 | (5.2) Building the extras (commons-logging, webservices etc.)
|
| 230 |
|
| 231 | These components are documented on the "Additional Components"
|
| 232 | (extras.html) page of documentation. They are built during a "release"
|
| 233 | build.
|
| 234 |
|
| 235 | You can build them by using the following commands:
|
| 236 |
|
| 237 | cd ${tomcat.source}
|
| 238 | ant extras
|
| 239 |
|
| 240 | (5.3) Building the embedded packages
|
| 241 |
|
| 242 | These are built during a "release" build.
|
| 243 |
|
| 244 | You can build them by using the following commands:
|
| 245 |
|
| 246 | cd ${tomcat.source}
|
| 247 | ant embed
|
| 248 |
|
| 249 |
|
| 250 | (6) Building a full release (as provided via the ASF download pages)
|
| 251 |
|
| 252 | 1. Configure GPG, if needed
|
| 253 |
|
| 254 | If the released artifacts have to be cryptographically signed with a
|
| 255 | PGP signature, like the official ASF releases are, the following
|
| 256 | property can be added to the build.properties file:
|
| 257 |
|
| 258 | # Location of GPG executable (used only for releases)
|
| 259 | gpg.exec=/path/to/gpg
|
| 260 |
|
| 261 | You do not need it if you do not plan to sign the release.
|
| 262 |
|
| 263 | If "gpg.exec" property does not point to an existing file, it will be
|
| 264 | ignored and this feature will be disabled.
|
| 265 |
|
| 266 | You will be prompted for the GPG passphrase when the release build
|
| 267 | starts, unless "gpg.passphrase" property is set.
|
| 268 |
|
| 269 | 2. Build the release:
|
| 270 |
|
| 271 | cd ${tomcat.source}
|
| 272 | ant release
|
| 273 |
|
| 274 |
|
| 275 | (7) Tests
|
| 276 |
|
| 277 | (7.1) Running Tomcat tests
|
| 278 |
|
| 279 | Tomcat includes a number of junit tests. The tests are not run when a
|
| 280 | release is built. There is separate command to run them.
|
| 281 |
|
| 282 | To run the testsuite use the following command:
|
| 283 |
|
| 284 | cd ${tomcat.source}
|
| 285 | ant test
|
| 286 |
|
| 287 | It is advisable to redirect output of the above command to a file for later
|
| 288 | inspection.
|
| 289 |
|
| 290 | The JUnit reports generated by the tests will be written to the following
|
| 291 | directory:
|
| 292 |
|
| 293 | output/build/logs
|
| 294 |
|
| 295 |
|
| 296 | By default the testsuite is run three times to test 3 different
|
| 297 | implementations of Tomcat connectors: BIO, NIO and APR. (If you are not
|
| 298 | familiar with Tomcat connectors, see config/http.html in documentation for
|
| 299 | details).
|
| 300 |
|
| 301 | The 3 runs are enabled and disabled individually by the following
|
| 302 | properties, which all are "true" by default:
|
| 303 |
|
| 304 | execute.test.bio=true
|
| 305 | execute.test.nio=true
|
| 306 | execute.test.apr=true
|
| 307 |
|
| 308 | The APR connector can be tested only if Tomcat-Native library binaries are
|
| 309 | found by the testsuite. The "test.apr.loc" property specifies the directory
|
| 310 | where the library binaries are located.
|
| 311 |
|
| 312 | By default the "test.apr.loc" property specifies the following location:
|
| 313 |
|
| 314 | output/build/bin/native/
|
| 315 |
|
| 316 | If you are on Windows and want to test the APR connector you can put the
|
| 317 | tcnative-1.dll file into ${tomcat.source}/bin/native/ and it will be copied
|
| 318 | into the above directory when the build runs.
|
| 319 |
|
| 320 |
|
| 321 | (7.2) Running a single test
|
| 322 |
|
| 323 | It is possible to run a single JUnit test class by adding the "test.entry"
|
| 324 | property to the build.properties file. The property specifies the name of
|
| 325 | the test class.
|
| 326 |
|
| 327 | For example:
|
| 328 |
|
| 329 | test.entry=org.apache.catalina.util.TestServerInfo
|
| 330 |
|
| 331 |
|
| 332 | (7.3) Other configuration options
|
| 333 |
|
| 334 | 1. It is possible to enable generation of access log file when the tests
|
| 335 | are run. This is off by default and can be enabled by the following
|
| 336 | property:
|
| 337 |
|
| 338 | test.accesslog=true
|
| 339 |
|
| 340 | The "access_log.<date>" file will be written to the same directory as
|
| 341 | JUnit reports,
|
| 342 |
|
| 343 | output/build/logs
|
| 344 |
|
| 345 | 2. The testsuite respects logging configuration as configured by
|
| 346 | ${tomcat.source}/conf/logging.properties
|
| 347 |
|
| 348 | The log files will be written to the temporary directory used by the
|
| 349 | tests,
|
| 350 |
|
| 351 | output/test-tmp/logs
|
| 352 |
|
| 353 | 3. It is possible to configure formatter used by JUnit reports. For
|
| 354 | example the following property disables generation of separate report
|
| 355 | files:
|
| 356 |
|
| 357 | junit.formatter.usefile=false
|
| 358 |
|
| 359 |
|
| 360 | (8) Source code checks
|
| 361 |
|
| 362 | (8.1) Checkstyle
|
| 363 |
|
| 364 | * NOTE: Checkstyle is licensed under LGPL. Using Checkstyle during Tomcat
|
| 365 | build is optional and is off by default.
|
| 366 |
|
| 367 | Tomcat comes with a Checkstyle configuration that tests its source code
|
| 368 | for certain conventions, like presence of the license header.
|
| 369 |
|
| 370 | To enable Checkstyle, add the following property to build.properties file:
|
| 371 |
|
| 372 | execute.validate=true
|
| 373 |
|
| 374 | Once Checkstyle is enabled, the check will be performed automatically
|
| 375 | during the build. The check is run before compilation of the source code.
|
| 376 |
|
| 377 | To speed-up repeated runs of this check, a cache is configured. The cache
|
| 378 | is located in the following directory:
|
| 379 |
|
| 380 | output/res/checkstyle
|
| 381 |
|
| 382 | It is possible to run the check separately by invoking the "validate"
|
| 383 | target. The command is:
|
| 384 |
|
| 385 | cd ${tomcat.source}
|
| 386 | ant -Dexecute.validate=true validate
|
| 387 |
|
| 388 |
|
| 389 | (8.2) End-of-line conventions check
|
| 390 |
|
| 391 | You usually would not need to run this check. You can skip this section.
|
| 392 |
|
| 393 | Apache Tomcat project has convention that all of its textual source files,
|
| 394 | stored in Subversion repository, are marked with Subversion property
|
| 395 | "svn:eol-style" with value of "native". This convention makes the editing
|
| 396 | of source code on different platforms easier.
|
| 397 |
|
| 398 | This test is used by developers to check that the source code adheres to
|
| 399 | this convention. It verifies that the ends of lines in textual files are
|
| 400 | appropriate for the operating system where it is run. The idea is to run
|
| 401 | this check regularly on two different platforms and notify developers when
|
| 402 | an inconsistency is detected.
|
| 403 |
|
| 404 | The command to run this test is:
|
| 405 |
|
| 406 | cd ${tomcat.source}
|
| 407 | ant validate-eoln
|