blob: 3f4e5b88c1ee879875df17bd8c83b29d4366fe29 [file] [log] [blame]
Hongqing Liufd5ee812014-05-10 16:32:51 +08001================================================================================
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 ====================================================
刘洪青6266f992017-05-15 21:21:03 +080019 Building The Apache Tomcat 7.0 Servlet/JSP Container
Hongqing Liufd5ee812014-05-10 16:32:51 +080020 ====================================================
21
刘洪青6266f992017-05-15 21:21:03 +080022This subproject contains the source code for Tomcat 7.0, a container that
23implements the Servlet 3.0, JSP 2.2, EL 2.2 and WebSocket 1.1 specifications
24from the Java Community Process <http://www.jcp.org/>.
Hongqing Liufd5ee812014-05-10 16:32:51 +080025
26Note: If you just need to run Apache Tomcat, it is not necessary to build
27it. You may simply download a binary distribution. It is cross-platform.
28Read RUNNING.txt for the instruction on how to run it.
29
30In order to build a binary distribution version of Apache Tomcat from a
31source distribution, do the following:
32
33
刘洪青6266f992017-05-15 21:21:03 +080034(1) Download and Install a Java 6 and Java 7 Development Kit
Hongqing Liufd5ee812014-05-10 16:32:51 +080035
刘洪青6266f992017-05-15 21:21:03 +080036 1. If the JDKs are already installed, skip to (2).
Hongqing Liufd5ee812014-05-10 16:32:51 +080037
刘洪青6266f992017-05-15 21:21:03 +080038 2. Download a version 6 of the Java Development Kit (JDK) release (use the
39 latest update available for your chosen version) from
Hongqing Liufd5ee812014-05-10 16:32:51 +080040
刘洪青6266f992017-05-15 21:21:03 +080041 http://www.oracle.com/technetwork/java/javase/downloads/index.html
42 or from another JDK vendor.
Hongqing Liufd5ee812014-05-10 16:32:51 +080043
刘洪青6266f992017-05-15 21:21:03 +080044 Note regarding later versions of Java:
Hongqing Liufd5ee812014-05-10 16:32:51 +080045
刘洪青6266f992017-05-15 21:21:03 +080046 As documented elsewhere, one of the components in Apache Tomcat includes
47 a private copy of the Apache Commons DBCP library. The source code
48 for this library is downloaded, processed by the build script
49 (renaming the packages) and compiled.
Hongqing Liufd5ee812014-05-10 16:32:51 +080050
刘洪青6266f992017-05-15 21:21:03 +080051 Due to changes in JDBC interfaces implemented by the library between
52 versions of Java SE specification, the library has to target specific
53 version of Java and can be compiled only with the JDK version
54 implementing this version of specification. Therefore, the build Tomcat
55 build process must be executed with a Java 6 JDK.
Hongqing Liufd5ee812014-05-10 16:32:51 +080056
刘洪青6266f992017-05-15 21:21:03 +080057 See Apache Commons DBCP project web site for more details on
58 available versions of the library and its requirements,
Hongqing Liufd5ee812014-05-10 16:32:51 +080059
刘洪青6266f992017-05-15 21:21:03 +080060 http://commons.apache.org/dbcp/
Hongqing Liufd5ee812014-05-10 16:32:51 +080061
刘洪青6266f992017-05-15 21:21:03 +080062 If you really want to use a later version of JDK to build Tomcat,
63 several workarounds are possible. One of them is to skip building
64 the component (tomcat-dbcp.jar).
Hongqing Liufd5ee812014-05-10 16:32:51 +080065
刘洪青6266f992017-05-15 21:21:03 +080066 3. Install the Java 6 JDK according to the instructions included with the
67 release.
Hongqing Liufd5ee812014-05-10 16:32:51 +080068
刘洪青6266f992017-05-15 21:21:03 +080069 4. Set an environment variable JAVA_HOME to the pathname of the directory
70 into which you installed the JDK release.
71
72 5. Download a version 7 of the Java Development Kit (JDK) release (use the
73 latest update available for your chosen version) from
74
75 http://www.oracle.com/technetwork/java/javase/downloads/index.html
76 or from another JDK vendor.
77
78 6. Install the Java 7 JDK according to the instructions included with the
79 release.
80
81* NOTE: The Java 7 JDK is only required if you wish to build Tomcat with
82 JSR-356 (Java WebSocket 1.1) support.
Hongqing Liufd5ee812014-05-10 16:32:51 +080083
84
刘洪青6266f992017-05-15 21:21:03 +080085(2) Install Apache Ant version 1.8.2 or later on your computer
Hongqing Liufd5ee812014-05-10 16:32:51 +080086
刘洪青6266f992017-05-15 21:21:03 +080087 1. If Apache Ant version 1.8.2 or later is already installed on your computer, skip to (3).
Hongqing Liufd5ee812014-05-10 16:32:51 +080088
刘洪青6266f992017-05-15 21:21:03 +080089 2. Download a binary distribution of Ant from:
Hongqing Liufd5ee812014-05-10 16:32:51 +080090
刘洪青6266f992017-05-15 21:21:03 +080091 http://ant.apache.org/bindownload.cgi
Hongqing Liufd5ee812014-05-10 16:32:51 +080092
刘洪青6266f992017-05-15 21:21:03 +080093 3. Unpack the binary distribution into a convenient location so that the
94 Ant release resides in its own directory (conventionally named
95 "apache-ant-[version]").
Hongqing Liufd5ee812014-05-10 16:32:51 +080096
刘洪青6266f992017-05-15 21:21:03 +080097 For the purposes of the remainder of this document, the symbolic name
98 "${ant.home}" is used to refer to the full pathname of the release
99 directory.
Hongqing Liufd5ee812014-05-10 16:32:51 +0800100
刘洪青6266f992017-05-15 21:21:03 +0800101 4. Create an ANT_HOME environment variable to point the directory
102 ${ant.home}.
103
104 5. Modify the PATH environment variable to include the directory
105 ${ant.home}/bin in its list. This makes the "ant" command line script
106 available, which will be used to actually perform the build.
Hongqing Liufd5ee812014-05-10 16:32:51 +0800107
108
刘洪青6266f992017-05-15 21:21:03 +0800109(3) Building Tomcat 7.0
Hongqing Liufd5ee812014-05-10 16:32:51 +0800110
刘洪青6266f992017-05-15 21:21:03 +0800111(3.1) Checkout or obtain the source code for Tomcat 7.0
Hongqing Liufd5ee812014-05-10 16:32:51 +0800112
刘洪青6266f992017-05-15 21:21:03 +0800113Checkout the source using SVN, selecting a tag for released version or
114trunk for the current development code, or download and unpack a source
115package.
Hongqing Liufd5ee812014-05-10 16:32:51 +0800116
刘洪青6266f992017-05-15 21:21:03 +0800117 * Tomcat SVN repository URL:
Hongqing Liufd5ee812014-05-10 16:32:51 +0800118
刘洪青6266f992017-05-15 21:21:03 +0800119 http://svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk/
Hongqing Liufd5ee812014-05-10 16:32:51 +0800120
刘洪青6266f992017-05-15 21:21:03 +0800121 * Source packages can be downloaded from:
Hongqing Liufd5ee812014-05-10 16:32:51 +0800122
刘洪青6266f992017-05-15 21:21:03 +0800123 http://tomcat.apache.org/download-70.cgi
Hongqing Liufd5ee812014-05-10 16:32:51 +0800124
刘洪青6266f992017-05-15 21:21:03 +0800125The location where the source has been placed will be further referred as
126${tomcat.source}.
Hongqing Liufd5ee812014-05-10 16:32:51 +0800127
刘洪青6266f992017-05-15 21:21:03 +0800128The Tomcat local build process does not modify line-endings. The svn repository
129is configured so that all files will be checked out with the line-ending
130appropriate for the current platform. When using a source package you should
131ensure that you use the source package that has the appropriate line-ending
132for your platform:
Hongqing Liufd5ee812014-05-10 16:32:51 +0800133
刘洪青6266f992017-05-15 21:21:03 +0800134 zip -> CRLF
135 tar.gz -> LF
Hongqing Liufd5ee812014-05-10 16:32:51 +0800136
刘洪青6266f992017-05-15 21:21:03 +0800137Note that the release build process does modify line-endings to ensure that
138each release package has the appropriate line-endings.
Hongqing Liufd5ee812014-05-10 16:32:51 +0800139
刘洪青6266f992017-05-15 21:21:03 +0800140(3.2) Building
Hongqing Liufd5ee812014-05-10 16:32:51 +0800141
刘洪青6266f992017-05-15 21:21:03 +0800142 1. The build is controlled by creating a ${tomcat.source}/build.properties
143 file.
Hongqing Liufd5ee812014-05-10 16:32:51 +0800144
刘洪青6266f992017-05-15 21:21:03 +0800145 It is recommended to always create the file, because of unfortunate
146 default value of base.path property. You may start with the following
147 content for the file:
148
149 # ----- Default Base Path for Dependent Packages -----
150 # Replace this path with the directory path where dependencies binaries
151 # should be downloaded
152 base.path=/home/me/some-place-to-download-to
153
154 2. Configure base.path property by adding it to the
155 ${tomcat.source}/build.properties file.
156
157 The base.path property specifies the place where Tomcat dependencies
158 required by the build are downloaded. It is recommended to place this
159 directory outside of the source tree, so that you do not waste your
160 time re-downloading the libraries.
161
162* NOTE: The default value of the base.path property configures the build script
163 to download the libraries required to build Tomcat to the
164 ${user.home}/tomcat-build-libs directory.
165
166* NOTE: Users accessing the Internet through a proxy must use the properties
167 file to indicate to Ant the proxy configuration.
168
169 The following properties should be added to the ${tomcat.source}/build.properties
170 file.
171
172 proxy.use=on
173 proxy.host=proxy.domain
174 proxy.port=8080
175 proxy.user=username
176 proxy.password=password
177
178 See Apache Ant documentation for the <setproxy> task for details.
179
180* NOTE: Users wishing to build Tomcat with JSR-356 (Java WebSocket 1.1) support
181 must also set the java.7.home build property to the location of the Java 7 JDK
182 installation.
183
184 3. Go to the sources directory and run Ant:
185
186 cd ${tomcat.source}
187 ant
188
189 This will execute the "deploy" target in build.xml.
190
191 Once the build has completed successfully, a usable Tomcat installation
192 will have been produced in the ${tomcat.source}/output/build directory,
193 and can be started and stopped with the usual scripts.
194
195 Note that the build includes Tomcat documentation, which can be found
196 in the output/build/webapps/docs directory.
197
198 The path of the output directory can be controlled by specifying the
199 "tomcat.output" property in the build.properties file.
200
201* NOTE: Do not run the build as the root user. Building and running Tomcat
202 does not require root privileges.
Hongqing Liufd5ee812014-05-10 16:32:51 +0800203
204
刘洪青6266f992017-05-15 21:21:03 +0800205(4) Updating sources and rebuilding
Hongqing Liufd5ee812014-05-10 16:32:51 +0800206
刘洪青6266f992017-05-15 21:21:03 +0800207It is recommended that you regularly update the downloaded Tomcat 7.0
208sources using your SVN client.
Hongqing Liufd5ee812014-05-10 16:32:51 +0800209
210For a quick rebuild of only modified code you can use:
刘洪青6266f992017-05-15 21:21:03 +0800211
Hongqing Liufd5ee812014-05-10 16:32:51 +0800212 cd ${tomcat.source}
213 ant
214
刘洪青6266f992017-05-15 21:21:03 +0800215
216(5) Special builds
217
218There are several targets in Tomcat build files that are useful to be
219called separately. They build components that you may want to build
220quickly, or ones that are included in the full release and are not built
221during the default "deploy" build.
222
223(5.1) Building documentation
224
225The documentation web application is built during the default "deploy"
226build.
227
228It can be built quickly by using the following commands:
Hongqing Liufd5ee812014-05-10 16:32:51 +0800229
230 cd ${tomcat.source}
刘洪青6266f992017-05-15 21:21:03 +0800231 ant build-docs
Hongqing Liufd5ee812014-05-10 16:32:51 +0800232
刘洪青6266f992017-05-15 21:21:03 +0800233The output of this command will be found in the following directory:
234
235 output/build/webapps/docs
236
237
238The API documentation (Javadoc) is built during a "release" build. It is
239easy to build it separately by using the following commands:
Hongqing Liufd5ee812014-05-10 16:32:51 +0800240
241 cd ${tomcat.source}
刘洪青6266f992017-05-15 21:21:03 +0800242 ant javadoc
Hongqing Liufd5ee812014-05-10 16:32:51 +0800243
刘洪青6266f992017-05-15 21:21:03 +0800244The output of this command will be found in the following directories:
245
246 output/dist/webapps/docs/api
247 output/dist/webapps/docs/elapi
248 output/dist/webapps/docs/jspapi
249 output/dist/webapps/docs/servletapi
250
251
252(5.2) Building the extras (commons-logging, webservices etc.)
253
254These components are documented on the "Additional Components"
255(extras.html) page of documentation. They are built during a "release"
256build.
257
258You can build them by using the following commands:
Hongqing Liufd5ee812014-05-10 16:32:51 +0800259
260 cd ${tomcat.source}
刘洪青6266f992017-05-15 21:21:03 +0800261 ant extras
262
263(5.3) Building the embedded packages
264
265These are built during a "release" build.
266
267You can build them by using the following commands:
268
269 cd ${tomcat.source}
270 ant embed
271
272
273(6) Building a full release (as provided via the ASF download pages)
274
275 A full release includes the Windows installer which requires a Windows
276 environment to be available to create it. If not building in a Windows
277 environment, the build scripts assume that Wine is available. If this is not
278 the case, the skip.installer property may be set to skip the creation of the
279 Windows installer.
280
281 1. Configure GPG, if needed
282
283 If the released artifacts have to be cryptographically signed with a
284 PGP signature, like the official ASF releases are, the following
285 property can be added to the build.properties file:
286
287 # Location of GPG executable (used only for releases)
288 gpg.exec=/path/to/gpg
289
290 You do not need it if you do not plan to sign the release.
291
292 If "gpg.exec" property does not point to an existing file, it will be
293 ignored and this feature will be disabled.
294
295 You will be prompted for the GPG passphrase when the release build
296 starts, unless "gpg.passphrase" property is set.
297
298 2. Build the release:
299
300 cd ${tomcat.source}
301 ant release
302
303
304(7) Tests
305
306(7.1) Running Tomcat tests
307
308Tomcat includes a number of junit tests. The tests are not run when a
309release is built. There is separate command to run them.
310
311To run the testsuite use the following command:
312
313 cd ${tomcat.source}
314 ant test
315
316It is advisable to redirect output of the above command to a file for later
317inspection.
318
319The JUnit reports generated by the tests will be written to the following
320directory:
321
322 output/build/logs
323
324
325By default the testsuite is run three times to test 3 different
326implementations of Tomcat connectors: BIO, NIO and APR. (If you are not
327familiar with Tomcat connectors, see config/http.html in documentation for
328details).
329
330The 3 runs are enabled and disabled individually by the following
331properties, which all are "true" by default:
332
333 execute.test.bio=true
334 execute.test.nio=true
335 execute.test.apr=true
336
337The APR connector can be tested only if Tomcat-Native library binaries are
338found by the testsuite. The "test.apr.loc" property specifies the directory
339where the library binaries are located.
340
341By default the "test.apr.loc" property specifies the following location:
342
343 output/build/bin/native/
344
345If you are on Windows and want to test the APR connector you can put the
346tcnative-1.dll file into ${tomcat.source}/bin/native/ and it will be copied
347into the above directory when the build runs.
348
349* NOTE: If you configured the build to use a Java 7 JDK (if the
350"java.7.home" property has been defined) the tests will be run with Java 7.
351
352The version of Java that was actually used to run the tests is reported by
353"org.apache.catalina.util.TestServerInfo" test class.
354
355
356(7.2) Running a single test
357
358It is possible to run a single JUnit test class by adding the "test.entry"
359property to the build.properties file. The property specifies the name of
360the test class.
361
362For example:
363
364 test.entry=org.apache.catalina.util.TestServerInfo
365
366It is possible to further limit such run to a number of selected test
367methods by adding "test.entry.methods" property. The property specifies a
368comma-separated list of test case methods. (This feature requires
369Apache Ant 1.8.2 or later).
370
371For example:
372
373 test.entry=org.apache.el.lang.TestELArithmetic
374 test.entry.methods=testMultiply01,testMultiply02
375
376
377(7.3) Running a set of tests
378
379It is possible to run a set of JUnit test classes by adding the "test.name"
380property to the build.properties file. The property specifies an Ant
381includes pattern for the fileset of test class files to run.
382
383The default value is "**/Test*.java", so all test classes are being
384executed (with few exceptions - see build.xml for several exclude patterns).
385
386You can include multiple patterns by concatenating them with a comma (",")
387as the separator.
388
389For example:
390
391 test.name=**/TestSsl.java,**/TestWebSocketFrameClientSSL.java
392
393
394(7.4) Other configuration options
395
396 1. It is possible to configure the directory where JUnit reports are
397 written to. It is configured by "test.reports" property. The default
398 value is
399
400 output/build/logs
401
402 2. It is possible to enable generation of access log file when the tests
403 are run. This is off by default and can be enabled by the following
404 property:
405
406 test.accesslog=true
407
408 The "access_log.<date>" file will be written to the same directory as
409 JUnit reports,
410
411 output/build/logs
412
413 3. The testsuite respects logging configuration as configured by
414 ${tomcat.source}/conf/logging.properties
415
416 The log files will be written to the temporary directory used by the
417 tests,
418
419 output/test-tmp/logs
420
421 4. It is possible to configure formatter used by JUnit reports.
422 Configuration properties are "junit.formatter.type",
423 "junit.formatter.extension" and "junit.formatter.usefile".
424
425 For example the following property disables generation of separate report
426 files:
427
428 junit.formatter.usefile=false
429
430 5. Optional support is provided for the Cobertura code coverage tool.
431
432* NOTE: Cobertura is licensed under GPL v2 with parts of it being under
433 Apache License v1.1. See http://cobertura.sf.net for details. Using it
434 during Tomcat build is optional and is off by default.
435
436 Cobertura can be enabled using the following property:
437
438 test.cobertura=true
439
440 The report files by default are written to
441
442 output/coverage
443
444 6. Some tests include checks that the access log valve entries are as expected.
445 These checks include timings. On slower / loaded systems these checks will
446 often fail. The checks may be relaxed by using the following property:
447
448 test.relaxTiming=true
449
450 7. It is known that some platforms (e.g. OSX El Capitan) require IPv4 to
451 be the default for the multicast tests to work. This is configured by
452 the following property:
453
454 java.net.preferIPv4Stack=true
455
456 8. It is possible to control whether the output of the tests is displayed
457 on the console or not. By default it is displayed and can be disabled
458 by the following property:
459
460 test.verbose=true
461
462(8) Source code checks
463
464(8.1) Checkstyle
465
466* NOTE: Checkstyle is licensed under LGPL. Using Checkstyle during Tomcat
467 build is optional and is off by default.
468
469Tomcat comes with a Checkstyle configuration that tests its source code
470for certain conventions, like presence of the license header.
471
472To enable Checkstyle, add the following property to build.properties file:
473
474 execute.validate=true
475
476Once Checkstyle is enabled, the check will be performed automatically
477during the build. The check is run before compilation of the source code.
478
479To speed-up repeated runs of this check, a cache is configured. The cache
480is located in the following directory:
481
482 output/res/checkstyle
483
484It is possible to run the check separately by invoking the "validate"
485target. The command is:
486
487 cd ${tomcat.source}
488 ant -Dexecute.validate=true validate
489
490
491(8.2) End-of-line conventions check
492
493You usually would not need to run this check. You can skip this section.
494
495Apache Tomcat project has convention that all of its textual source files,
496stored in Subversion repository, are marked with Subversion property
497"svn:eol-style" with value of "native". This convention makes the editing
498of source code on different platforms easier.
499
500This test is used by developers to check that the source code adheres to
501this convention. It verifies that the ends of lines in textual files are
502appropriate for the operating system where it is run. The idea is to run
503this check regularly on two different platforms and notify developers when
504an inconsistency is detected.
505
506The command to run this test is:
507
508 cd ${tomcat.source}
509 ant validate-eoln