Blame | Last modification | View Log | Download | RSS feed
================================================================================Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.====================================================================================================================================Building The Apache Tomcat 9.0 Servlet/JSP Container====================================================This project contains the source code for Tomcat 9.0, a container thatimplements the Servlet 4.0, JSP 2.3, EL 3.0, WebSocket 1.1 and JASPIC 1.1specifications from the Java Community Process <https://www.jcp.org/>.Note: If you just need to run Apache Tomcat, it is not necessary to buildit. You may simply download a binary distribution. It is cross-platform.Read RUNNING.txt for the instruction on how to run it.In order to build a binary distribution version of Apache Tomcat from asource distribution, do the following:(1) Download and Install a Java Development Kit1. If the JDK is already installed, skip to (2).2. Download a version 17 or later of Java Development Kit (JDK) release (usethe latest update available for your chosen version) from one of:http://www.oracle.com/technetwork/java/javase/downloads/index.htmlhttp://openjdk.java.net/install/index.htmlor another JDK vendor.Note regarding later versions of Java:As documented elsewhere, one of components in Apache Tomcat includesa private copy of the Apache Commons DBCP 2 library.The JDBC interfaces implemented by DBCP frequently change in non-backwardscompatible ways between versions of the Java SE specification. Therefore,it is likely that DBCP 2 will only compile with the specific version of Javalisted above and that compilation will fail if a later version of Java isused.See Apache Commons DBCP 2 project web site for more details onavailable versions of the library and its requirements,https://commons.apache.org/dbcp/3. Install the JDK according to the instructions included with the release.4. Set an environment variable JAVA_HOME to the pathname of the directoryinto which you installed the JDK release.(2) Install Apache Ant version 1.10.2 or later on your computer.1. If Apache Ant version 1.10.2 or later is already installed on yourcomputer, skip to (3).2. Download a binary distribution of Ant from:https://ant.apache.org/bindownload.cgi3. Unpack the binary distribution into a convenient location so that theAnt release resides in its own directory (conventionally named"apache-ant-[version]").For the purposes of the remainder of this document, the symbolic name"${ant.home}" is used to refer to the full pathname of the releasedirectory.4. Create an ANT_HOME environment variable to point the directory${ant.home}.5. Modify the PATH environment variable to include the directory${ant.home}/bin in its list. This makes the "ant" command line scriptavailable, which will be used to actually perform the build.(3) Building Tomcat 9.0(3.1) Checkout or obtain the source code for Tomcat 9.0Clone the source using git, then checkout a specific major branch ormain for the latest code development, or download and unpack a sourcepackage.* Tomcat GitHub repository URL:https://github.com/apache/tomcat* Source packages can be downloaded from:https://tomcat.apache.org/download-90.cgiThe location where the source has been placed will be further referred as${tomcat.source}.The Tomcat local build process does not modify line-endings. The svn repositoryis configured so that all files will be checked out with the line-endingappropriate for the current platform. When using a source package you shouldensure that you use the source package that has the appropriate line-endingfor your platform:zip -> CRLFtar.gz -> LFNote that the release build process does modify line-endings to ensure thateach release package has the appropriate line-endings.(3.2) Building1. The build is controlled by creating a ${tomcat.source}/build.propertiesfile.It is recommended to always create the file, because of unfortunatedefault value of base.path property. You may start with the followingcontent for the file:# ----- Default Base Path for Dependent Packages -----# Replace this path with the directory path where dependencies binaries# should be downloadedbase.path=/home/me/some-place-to-download-to2. Configure base.path property by adding it to the${tomcat.source}/build.properties file.The base.path property specifies the place where Tomcat dependenciesrequired by the build are downloaded. It is recommended to place thisdirectory outside of the source tree, so that you do not waste yourtime re-downloading the libraries.* NOTE: The default value of the base.path property configures the build scriptto download the libraries required to build Tomcat to the${user.home}/tomcat-build-libs directory.* NOTE: Users accessing the Internet through a proxy must use the propertiesfile to indicate to Ant the proxy configuration.The following properties should be added to the ${tomcat.source}/build.propertiesfile.proxy.use=trueproxy.host=proxy.domainproxy.port=8080proxy.user=usernameproxy.password=passwordSee Apache Ant documentation for the <setproxy> task for details.3. Go to the sources directory and run Ant:cd ${tomcat.source}antThis will execute the "deploy" target in build.xml.Once the build has completed successfully, a usable Tomcat installationwill have been produced in the ${tomcat.source}/output/build directory,and can be started and stopped with the usual scripts.Note that the build includes Tomcat documentation, which can be foundin the output/build/webapps/docs directory.The path of the output directory can be controlled by specifying the"tomcat.output" property in the build.properties file.* NOTE: Do not run the build as the root user. Building and running Tomcatdoes not require root privileges.(4) Updating sources and rebuildingIt is recommended that you regularly update the downloaded Tomcat 9.0sources using your git client.For a quick rebuild of only modified code you can use:cd ${tomcat.source}ant(5) Special buildsThere are several targets in Tomcat build files that are useful to becalled separately. They build components that you may want to buildquickly, or ones that are included in the full release and are not builtduring the default "deploy" build.(5.1) Building documentationThe documentation web application is built during the default "deploy"build.It can be built quickly by using the following commands:cd ${tomcat.source}ant build-docsThe output of this command will be found in the following directory:output/build/webapps/docsThe API documentation (Javadoc) is built during a "release" build. It iseasy to build it separately by using the following commands:cd ${tomcat.source}ant javadocThe output of this command will be found in the following directories:output/dist/webapps/docs/apioutput/dist/webapps/docs/elapioutput/dist/webapps/docs/jspapioutput/dist/webapps/docs/servletapi(5.2) Building the extras (commons-logging, webservices etc.)These components are documented on the "Additional Components"(extras.html) page of documentation. They are built during a "release"build.You can build them by using the following commands:cd ${tomcat.source}ant extras(5.3) Building the embedded packagesThese are built during a "release" build.You can build them by using the following commands:cd ${tomcat.source}ant embed(5.4) Building the Windows installerThe Windows installer uses the NSIS installer framework.It can be build on Windows, on any other platform which providesthe Wine Windows emulator or the NSIS binary "makensis".Linux and MacOS are platforms, on which you can install Wine or"makensis".Selecting between Wine and makensis on non-Windows platforms canbe done by setting the ant property "nsis.tool" to either "wine"or "makensis" in build.properties.If you want to sign the installer, you will need to set someproperties with names prefixed with "codesigning" in your build.properties.For details see the targets "jsign-installer" and "jsign-uninstaller"in build.xml and the default property values in build.properties.default.(6) Building a full release (as provided via the ASF download pages)1. Remark on building the Windows installerA full release includes the Windows installer which requires a Windowsenvironment, an installed Wine emulator or an installed native"makensis" binary from the NSIS project. Creating a reproducibleinstaller using the "makensis" option needs a special build of "makensis".For details see below.Provided that Wine or "makensis" is available on non-Windows platforms,a full release build may be made on Windows, Linux or MacOS.If you do not want to build the Windows installer, the skip.installerproperty may be set to skip the creation of the Windows installer.2. Configure GPG, if neededIf the released artifacts have to be cryptographically signed with aPGP signature, like the official ASF releases are, the followingproperty can be added to the build.properties file:# Location of GPG executable (used only for releases)gpg.exec=/path/to/gpgYou do not need it if you do not plan to sign the release.If "gpg.exec" property does not point to an existing file, it will beignored and this feature will be deactivated.You will be prompted for the GPG passphrase when the release buildstarts, unless "gpg.passphrase" property is set.3. If building the Windows installer on WindowsIf running the build in a UAC enabled environment, building the Windowsinstaller requires elevated privileges. The simplest way to do this is toopen the command prompt used for the build with the "Run as administrator"option.4. Configure the code signing serviceASF committers performing official releases will need to configure the codesigning service so that the Windows installer is signed during the buildprocess. The following properties need to be added to the build.propertiesfile:# Location of GPG executable (used only for releases)gpg.exec=/path/to/gpg# Code signing of Windows installerdo.codesigning=truecodesigning.storepass=request-via-pmccodesigning.keypass=request-via-pmcRelease managers will be provided with the necessary credentials by the PMC.If you want to verify the installer from a release by rebuilding it,you can use the detached signatures provided in the official releases.In this case you have to use the sources from the source releasearchive, which contains these signatures. You also have to buildon Windows, use Wine, or use a special build of makensis to createa reproducible installer, that fits the signature files.5. Using a special "makensis" build on non-Windows (optional)If you want to build a reproducible installer on non-Windowsby using "makensis" instead of "Wine", you need to build"makensis" from a source download yourself. To build "makensis",you need python, scons and a C compiler. You can build "makensis"via an Ant target:ant local-makensisor you can build it manually using the following recipe.First detect the needed version by looking for nsis.versionin build.properties.default.Download and extract NSIS for Windows by running "ant download-dist". Notethe NSIS installation path from the output or by checking "nsis.bin.home" inbuild.properties.default. For example by default:nsis.bin.home=${base.path}/nsis-${nsis.version}The corresponding sources will be downloaded to "nsis.src.home" inbuild.properties.default. For example by default:nsis.src.home=${base.path}/nsis-${nsis.version}-srcInstall the scons Python software construction tool.Run the following command in the extracted NSIS source directory:scons UNICODE=yes PREFIX=${base.path}/nsis-${nsis.version}/Bin SKIPPLUGINS=all SKIPUTILS=all SKIPMISC=all NSIS_CONFIG_CONST_DATA_PATH=no VERSION=${nsis.version} install-compilerYou need to specify the correct value in VERSION (this ends up in the installer binaryso it needs to match). The PREFIX is not important, but you need to make surethat the created binary "makensis" gets finally put into the "Bin" directory ofthe NSIS binary distribution that "ant download-dist" installed. When using"NSIS_CONFIG_CONST_DATA_PATH=no" the binary is independent of the value of "PREFIX".In addition set the ant property "nsis.tool" to "makensis" inbuild.properties.6. Build the release:Apache Tomcat releases are fully reproducible.Release managers producing release builds must follow the followingprocedure:cd ${tomcat.source}ant pre-releaseant releasegit commit -a -m "Tag <version-number>"git tag <vesion-number>git push origin <version-number>ant releasegit reset --hard HEAD~1The output from either 'ant release' call may be uploaded as the officialrelease since they will be identical. It is recommended that the output fromthe second call is used.Anyone wishing to reproduce an official build must do so from an officialsource release. The build tool chain defined in build.properties.releasemust be used to reproduce an official build. Once unpacked to${tomcat.source}, the following steps must be followedcd ${tomcat.source}ant releaseFollowing the same steps without using the defined build tool chain willcreate a release that is functionally the same as an official release butnot bit for bit identical.(7) Tests(7.1) Running Tomcat testsTomcat includes a number of junit tests. The tests are not run when arelease is built. There is separate command to run them.To run the testsuite use the following command:cd ${tomcat.source}ant testIt is advisable to redirect output of the above command to a file for laterinspection.The JUnit reports generated by the tests will be written to the followingdirectory:output/build/logsBy default the testsuite is run three times to test 3 differentimplementations of Tomcat connectors: NIO, NIO2 and APR. (If you are notfamiliar with Tomcat connectors, see config/http.html in documentation fordetails).The 3 runs are activated and deactivated individually by the followingproperties, which all are "true" by default:execute.test.nio=trueexecute.test.nio2=trueexecute.test.apr=trueThe APR connector can be tested only if Tomcat-Native library binaries arefound by the testsuite. The "test.apr.loc" property specifies the directorywhere the library binaries are located.By default the "test.apr.loc" property specifies the following location:output/build/bin/If you are on Windows and want to test the APR connector you can put thetcnative-1.dll file into ${tomcat.source}/bin/ and it will be copiedinto the above directory when the build runs.The unit tests include tests of the clustering functionality which requiremulticast to be enabled. There is a simple application provided in the Tomcattest source (org.apache.catalina.tribes.TesterMulticast) that can be used tocheck if a machine supports multicast. Notes on enabling multicast for differentoperating systems are provided in the Javadoc for that class.(7.2) Running a single testIt is possible to run a single JUnit test class by adding the "test.entry"property to the build.properties file. The property specifies the name ofthe test class.For example:test.entry=org.apache.catalina.util.TestServerInfoIt is possible to further limit such run to a number of selected testmethods by adding "test.entry.methods" property. The property specifies acomma-separated list of test case methods.For example:test.entry=org.apache.el.lang.TestELArithmetictest.entry.methods=testMultiply01,testMultiply02(7.3) Running a set of testsIt is possible to run a set of JUnit test classes by adding the "test.name"property to the build.properties file. The property specifies an Antincludes pattern for the fileset of test class files to run.The default value is "**/Test*.java", so all test classes are beingexecuted (with few exceptions - see build.xml for several exclude patterns).You can include multiple patterns by concatenating them with a comma (",")as the separator.For example:test.name=**/TestSsl.java,**/TestWebSocketFrameClientSSL.javaYou can exclude specific JUnit test classes by adding the "test.exclude"property to the build.properties file. The property specifies an Antexcludes pattern for the fileset of test class files to exclude form the run.The default value is empty, so no classes are excluded. The syntax is the sameas for the property "test.name".(7.4) Other configuration options1. It is possible to configure the directory where JUnit reports arewritten to. It is configured by "test.reports" property. The defaultvalue isoutput/build/logs2. It is possible to enable generation of access log file when the testsare run. This is off by default and can be enabled by the followingproperty:test.accesslog=trueThe "access_log.<date>" file will be written to the same directory asJUnit reports,output/build/logs3. The testsuite respects logging configuration as configured by${tomcat.source}/conf/logging.propertiesThe log files will be written to the temporary directory used by thetests,output/test-tmp/logs4. It is possible to configure formatter used by JUnit reports.Configuration properties are "junit.formatter.type","junit.formatter.extension" and "junit.formatter.usefile".For example the following property deactivates generation of separate reportfiles:junit.formatter.usefile=false5. It is possible to speed up testing by letting JUnit to run severaltests in parallel.This is configured by setting "test.threads" property. The recommendedvalue is one thread per core.6. Optional support is provided for the Cobertura code coverage tool.NOTE: Cobertura is licensed under GPL v2 with parts of it being underApache License v1.1. See https://cobertura.github.io/cobertura/ for details.Using it during Tomcat build is optional and is off by default.Cobertura can be enabled using the following properties:test.cobertura=truetest.threads=1Using Cobertura currently requires setting test.threads configurationproperty to the value of 1. Setting that property to a different valuewill deactivate code coverage.The report files by default are written tooutput/coverage7. The performance tests are written to run on reasonably powerful machines(such as a developer may use day to day) assuming no other resource hungryprocesses are running.Performance tests may be an absolute test (how long to complete a numberof iterations of an operation or set of operations) or may be a relativetest (how long two or more different approaches take to generate the sameresult). The absolute tests may be destructive in that they run until thesystem runs out of resources.Where there is no benefit in running an absolute performance test as partof a standard test run, the test will be excluded by naming itTester*Performance.java.The relative tests are included as part of a standard test run however,where the assumptions made about host capabilities are not true (e.g. onCI systems running in virtual machine) the tests may be deactivated byusing the following property:test.excludePerformance=true8. Some tests are require large heaps (e.g. 8GB). The CI systems used by theproject either cannot support heaps of this size or do not support them bydefault. These tests are therefore disabled by default and may be enabled byusing the following property:test.includeLargeHeap=true9. Some tests include checks that the access log valve entries are as expected.These checks include timings. On slower / loaded systems these checks willoften fail. The checks may be relaxed by using the following property:test.relaxTiming=true10. It is known that some platforms (e.g. OSX El Capitan) require IPv4 tobe the default for the multicast tests to work. This is configured bythe following property:java.net.preferIPv4Stack=true11. By default the output of unit tests is sent to the console and can bequite verbose. The output can be deactivated by setting the property:test.verbose=false(8) Source code checks(8.1) CheckstyleNOTE: Checkstyle is licensed under LGPL. Using Checkstyle during Tomcatbuild is optional and is off by default.See http://checkstyle.sourceforge.net/ for more information.Tomcat comes with a Checkstyle configuration that tests its source codefor certain conventions, like presence of the license header.To enable Checkstyle, add the following property to build.properties file:execute.validate=trueOnce Checkstyle is enabled, the check will be performed automaticallyduring the build. The check is run before compilation of the source code.To speed-up repeated runs of this check, a cache is configured. The cacheis located in the following directory:output/res/checkstyleIt is possible to run the check separately by calling the "validate"target. The command is:cd ${tomcat.source}ant -Dexecute.validate=true validate(8.2) SpotBugsNOTE: SpotBugs is licensed under LGPL. Using SpotBugs during Tomcat build isoptional and is off by default.See https://spotbugs.github.io/ for more information.To enable SpotBugs, add the following property to build.properties file:execute.spotbugs=trueTo compile Tomcat classes and generate a SpotBugs report, call the"spotbugs" target. For example:cd ${tomcat.source}ant -Dexecute.spotbugs=true spotbugsThe report file by default is written tooutput/spotbugs(8.3) End-of-line conventions checkYou usually would not need to run this check. You can skip this section.Apache Tomcat project has convention that all of its textual source files,stored in the Git repository, use Unix style LF line endings.This test is used by developers to check that the source code adheres tothis convention. It verifies that the ends of lines in textual files areappropriate. The idea is to run this check regularly and notify developerswhen an inconsistency is detected.The command to run this test is:cd ${tomcat.source}ant validate-eoln