BUILDING.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ================================================================================
  15. ====================================================
  16. Building The Apache Tomcat 8.5 Servlet/JSP Container
  17. ====================================================
  18. This subproject contains the source code for Tomcat 8.5, a container that
  19. implements the Servlet 3.1, JSP 2.3, EL 3.0, WebSocket 1.1 and JASPIC 1.1
  20. specifications from the Java Community Process <https://www.jcp.org/>.
  21. Note: If you just need to run Apache Tomcat, it is not necessary to build
  22. it. You may simply download a binary distribution. It is cross-platform.
  23. Read RUNNING.txt for the instruction on how to run it.
  24. In order to build a binary distribution version of Apache Tomcat from a
  25. source distribution, do the following:
  26. (1) Download and Install a Java Development Kit
  27. 1. If the JDK is already installed, skip to (2).
  28. 2. Download a version 7 of Java Development Kit (JDK) release (use the
  29. latest update available for your chosen version) from one of:
  30. http://www.oracle.com/technetwork/java/javase/downloads/index.html
  31. http://openjdk.java.net/install/index.html
  32. or another JDK vendor.
  33. Note regarding later versions of Java:
  34. As documented elsewhere, one of components in Apache Tomcat includes
  35. a private copy of the Apache Commons DBCP 2 library.
  36. The JDBC interfaces implemented by DBCP frequently change in non-backwards
  37. compatible ways between versions of the Java SE specification. Therefore,
  38. it is likely that DBCP 2 will only compile with the specific version of Java
  39. listed above and that compilation will fail if a later version of Java is
  40. used.
  41. See Apache Commons DBCP 2 project web site for more details on
  42. available versions of the library and its requirements,
  43. https://commons.apache.org/dbcp/
  44. 3. Install the JDK according to the instructions included with the release.
  45. 4. Set an environment variable JAVA_HOME to the pathname of the directory
  46. into which you installed the JDK release.
  47. (2) Install Apache Ant version 1.9.10 or later on your computer.
  48. 1. If Apache Ant version 1.9.10 or later is already installed on your
  49. computer, skip to (3).
  50. 2. Download a binary distribution of Ant from:
  51. https://ant.apache.org/bindownload.cgi
  52. 3. Unpack the binary distribution into a convenient location so that the
  53. Ant release resides in its own directory (conventionally named
  54. "apache-ant-[version]").
  55. For the purposes of the remainder of this document, the symbolic name
  56. "${ant.home}" is used to refer to the full pathname of the release
  57. directory.
  58. 4. Create an ANT_HOME environment variable to point the directory
  59. ${ant.home}.
  60. 5. Modify the PATH environment variable to include the directory
  61. ${ant.home}/bin in its list. This makes the "ant" command line script
  62. available, which will be used to actually perform the build.
  63. (3) Building Tomcat 8.5
  64. (3.1) Checkout or obtain the source code for Tomcat 8.5
  65. Clone the source using git, then checkout a specific major branch or
  66. master for the latest code development, or download and unpack a source
  67. package.
  68. * Tomcat GitHub repository URL:
  69. https://github.com/apache/tomcat
  70. * Source packages can be downloaded from:
  71. https://tomcat.apache.org/download-80.cgi
  72. The location where the source has been placed will be further referred as
  73. ${tomcat.source}.
  74. The Tomcat local build process does not modify line-endings. The svn repository
  75. is configured so that all files will be checked out with the line-ending
  76. appropriate for the current platform. When using a source package you should
  77. ensure that you use the source package that has the appropriate line-ending
  78. for your platform:
  79. zip -> CRLF
  80. tar.gz -> LF
  81. Note that the release build process does modify line-endings to ensure that
  82. each release package has the appropriate line-endings.
  83. (3.2) Building
  84. 1. The build is controlled by creating a ${tomcat.source}/build.properties
  85. file.
  86. It is recommended to always create the file, because of unfortunate
  87. default value of base.path property. You may start with the following
  88. content for the file:
  89. # ----- Default Base Path for Dependent Packages -----
  90. # Replace this path with the directory path where dependencies binaries
  91. # should be downloaded
  92. base.path=/home/me/some-place-to-download-to
  93. 2. Configure base.path property by adding it to the
  94. ${tomcat.source}/build.properties file.
  95. The base.path property specifies the place where Tomcat dependencies
  96. required by the build are downloaded. It is recommended to place this
  97. directory outside of the source tree, so that you do not waste your
  98. time re-downloading the libraries.
  99. * NOTE: The default value of the base.path property configures the build script
  100. to download the libraries required to build Tomcat to the
  101. ${user.home}/tomcat-build-libs directory.
  102. * NOTE: Users accessing the Internet through a proxy must use the properties
  103. file to indicate to Ant the proxy configuration.
  104. The following properties should be added to the ${tomcat.source}/build.properties
  105. file.
  106. proxy.use=true
  107. proxy.host=proxy.domain
  108. proxy.port=8080
  109. proxy.user=username
  110. proxy.password=password
  111. See Apache Ant documentation for the <setproxy> task for details.
  112. 3. Go to the sources directory and run Ant:
  113. cd ${tomcat.source}
  114. ant
  115. This will execute the "deploy" target in build.xml.
  116. Once the build has completed successfully, a usable Tomcat installation
  117. will have been produced in the ${tomcat.source}/output/build directory,
  118. and can be started and stopped with the usual scripts.
  119. Note that the build includes Tomcat documentation, which can be found
  120. in the output/build/webapps/docs directory.
  121. The path of the output directory can be controlled by specifying the
  122. "tomcat.output" property in the build.properties file.
  123. * NOTE: Do not run the build as the root user. Building and running Tomcat
  124. does not require root privileges.
  125. (4) Updating sources and rebuilding
  126. It is recommended that you regularly update the downloaded Tomcat 8.5
  127. sources using your git client.
  128. For a quick rebuild of only modified code you can use:
  129. cd ${tomcat.source}
  130. ant
  131. (5) Special builds
  132. There are several targets in Tomcat build files that are useful to be
  133. called separately. They build components that you may want to build
  134. quickly, or ones that are included in the full release and are not built
  135. during the default "deploy" build.
  136. (5.1) Building documentation
  137. The documentation web application is built during the default "deploy"
  138. build.
  139. It can be built quickly by using the following commands:
  140. cd ${tomcat.source}
  141. ant build-docs
  142. The output of this command will be found in the following directory:
  143. output/build/webapps/docs
  144. The API documentation (Javadoc) is built during a "release" build. It is
  145. easy to build it separately by using the following commands:
  146. cd ${tomcat.source}
  147. ant javadoc
  148. The output of this command will be found in the following directories:
  149. output/dist/webapps/docs/api
  150. output/dist/webapps/docs/elapi
  151. output/dist/webapps/docs/jspapi
  152. output/dist/webapps/docs/servletapi
  153. (5.2) Building the extras (commons-logging, webservices etc.)
  154. These components are documented on the "Additional Components"
  155. (extras.html) page of documentation. They are built during a "release"
  156. build.
  157. You can build them by using the following commands:
  158. cd ${tomcat.source}
  159. ant extras
  160. (5.3) Building the embedded packages
  161. These are built during a "release" build.
  162. You can build them by using the following commands:
  163. cd ${tomcat.source}
  164. ant embed
  165. (6) Building a full release (as provided via the ASF download pages)
  166. A full release includes the Windows installer which requires a Windows
  167. environment to be available to create it. If not building in a Windows
  168. environment, the build scripts assume that Wine is available. If this is not
  169. the case, the skip.installer property may be set to skip the creation of the
  170. Windows installer.
  171. 1. Configure GPG, if needed
  172. If the released artifacts have to be cryptographically signed with a
  173. PGP signature, like the official ASF releases are, the following
  174. property can be added to the build.properties file:
  175. # Location of GPG executable (used only for releases)
  176. gpg.exec=/path/to/gpg
  177. You do not need it if you do not plan to sign the release.
  178. If "gpg.exec" property does not point to an existing file, it will be
  179. ignored and this feature will be disabled.
  180. You will be prompted for the GPG passphrase when the release build
  181. starts, unless "gpg.passphrase" property is set.
  182. 2. If building the Windows installer
  183. If running the build in a UAC enabled environment, building the Windows
  184. installer requires elevated privileges. The simplest way to do this is to
  185. open the command prompt used for the build with the "Run as administrator"
  186. option.
  187. 3. Configure the code signing service
  188. ASF committers performing official releases will need to configure the code
  189. signing service so that the Windows installer is signed during the build
  190. process. The following properties need to be added to the build.properties
  191. file:
  192. # Location of GPG executable (used only for releases)
  193. # Code signing of Windows installer
  194. do.codesigning=true
  195. codesigning.user=request-via-pmc
  196. codesigning.pwd=request-via-pmc
  197. codesigning.partnercode=request-via-pmc
  198. codesigning.service=Microsoft Windows Signing
  199. Release managers will be provided with the necessary credentials by the PMC.
  200. It will also be necessary to enable TLS 1.1 and TLS 1.2 by default (they are
  201. disabled by default on Java 7) for the build process to communicate with the
  202. code signing service. The simplest way is by setting the ANT_OPTS
  203. environment variable. E.g. (for Windows):
  204. set ANT_OPTS=-Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2
  205. 4. Build the release:
  206. cd ${tomcat.source}
  207. ant release
  208. (7) Tests
  209. (7.1) Running Tomcat tests
  210. Tomcat includes a number of junit tests. The tests are not run when a
  211. release is built. There is separate command to run them.
  212. To run the testsuite use the following command:
  213. cd ${tomcat.source}
  214. ant test
  215. It is advisable to redirect output of the above command to a file for later
  216. inspection.
  217. The JUnit reports generated by the tests will be written to the following
  218. directory:
  219. output/build/logs
  220. By default the testsuite is run three times to test 3 different
  221. implementations of Tomcat connectors: NIO, NIO2 and APR. (If you are not
  222. familiar with Tomcat connectors, see config/http.html in documentation for
  223. details).
  224. The 3 runs are enabled and disabled individually by the following
  225. properties, which all are "true" by default:
  226. execute.test.nio=true
  227. execute.test.nio2=true
  228. execute.test.apr=true
  229. The APR connector can be tested only if Tomcat-Native library binaries are
  230. found by the testsuite. The "test.apr.loc" property specifies the directory
  231. where the library binaries are located.
  232. By default the "test.apr.loc" property specifies the following location:
  233. output/build/bin/native/
  234. If you are on Windows and want to test the APR connector you can put the
  235. tcnative-1.dll file into ${tomcat.source}/bin/native/ and it will be copied
  236. into the above directory when the build runs.
  237. The unit tests include tests of the clustering functionality which require
  238. multicast to be enabled. There is a simple application provided in the Tomcat
  239. test source (org.apache.catalina.tribes.TesterMulticast) that can be used to
  240. check if a machine supports multicast. Notes on enabling multicast for different
  241. operating systems are provided in the Javadoc for that class.
  242. (7.2) Running a single test
  243. It is possible to run a single JUnit test class by adding the "test.entry"
  244. property to the build.properties file. The property specifies the name of
  245. the test class.
  246. For example:
  247. test.entry=org.apache.catalina.util.TestServerInfo
  248. It is possible to further limit such run to a number of selected test
  249. methods by adding "test.entry.methods" property. The property specifies a
  250. comma-separated list of test case methods.
  251. For example:
  252. test.entry=org.apache.el.lang.TestELArithmetic
  253. test.entry.methods=testMultiply01,testMultiply02
  254. (7.3) Running a set of tests
  255. It is possible to run a set of JUnit test classes by adding the "test.name"
  256. property to the build.properties file. The property specifies an Ant
  257. includes pattern for the fileset of test class files to run.
  258. The default value is "**/Test*.java", so all test classes are being
  259. executed (with few exceptions - see build.xml for several exclude patterns).
  260. You can include multiple patterns by concatenating them with a comma (",")
  261. as the separator.
  262. For example:
  263. test.name=**/TestSsl.java,**/TestWebSocketFrameClientSSL.java
  264. You can exclude specific JUnit test classes by adding the "test.exclude"
  265. property to the build.properties file. The property specifies an Ant
  266. excludes pattern for the fileset of test class files to exclude form the run.
  267. The default value is empty, so no classes are excluded. The syntax is the same
  268. as for the property "test.name".
  269. (7.4) Other configuration options
  270. 1. It is possible to configure the directory where JUnit reports are
  271. written to. It is configured by "test.reports" property. The default
  272. value is
  273. output/build/logs
  274. 2. It is possible to enable generation of access log file when the tests
  275. are run. This is off by default and can be enabled by the following
  276. property:
  277. test.accesslog=true
  278. The "access_log.<date>" file will be written to the same directory as
  279. JUnit reports,
  280. output/build/logs
  281. 3. The testsuite respects logging configuration as configured by
  282. ${tomcat.source}/conf/logging.properties
  283. The log files will be written to the temporary directory used by the
  284. tests,
  285. output/test-tmp/logs
  286. 4. It is possible to configure formatter used by JUnit reports.
  287. Configuration properties are "junit.formatter.type",
  288. "junit.formatter.extension" and "junit.formatter.usefile".
  289. For example the following property disables generation of separate report
  290. files:
  291. junit.formatter.usefile=false
  292. 5. It is possible to speed up testing by letting JUnit to run several
  293. tests in parallel.
  294. This is configured by setting "test.threads" property. The recommended
  295. value is one thread per core.
  296. 6. Optional support is provided for the Cobertura code coverage tool.
  297. NOTE: Cobertura is licensed under GPL v2 with parts of it being under
  298. Apache License v1.1. See https://cobertura.github.io/cobertura/ for details.
  299. Using it during Tomcat build is optional and is off by default.
  300. Cobertura can be enabled using the following properties:
  301. test.cobertura=true
  302. test.threads=1
  303. Using Cobertura currently requires setting test.threads configuration
  304. property to the value of 1. Setting that property to a different value
  305. will disable code coverage.
  306. The report files by default are written to
  307. output/coverage
  308. 7. The performance tests are written to run reasonably powerful machines (such
  309. as a developer may use day to day) assuming no other resource hungry
  310. processes are running.
  311. These assumptions are not always true (e.g. on CI systems running in a
  312. virtual machine) so the performance tests may be disabled by using the
  313. following property:
  314. test.excludePerformance=true
  315. 8. Some tests include checks that the access log valve entries are as expected.
  316. These checks include timings. On slower / loaded systems these checks will
  317. often fail. The checks may be relaxed by using the following property:
  318. test.relaxTiming=true
  319. 9. It is known that some platforms (e.g. OSX El Capitan) require IPv4 to
  320. be the default for the multicast tests to work. This is configured by
  321. the following property:
  322. java.net.preferIPv4Stack=true
  323. 10. By default the output of unit tests is sent to the console and can be
  324. quite verbose. The output can be disabled by setting the property:
  325. test.verbose=false
  326. (8) Source code checks
  327. (8.1) Checkstyle
  328. NOTE: Checkstyle is licensed under LGPL. Using Checkstyle during Tomcat
  329. build is optional and is off by default.
  330. See http://checkstyle.sourceforge.net/ for more information.
  331. Tomcat comes with a Checkstyle configuration that tests its source code
  332. for certain conventions, like presence of the license header.
  333. To enable Checkstyle, add the following property to build.properties file:
  334. execute.validate=true
  335. Once Checkstyle is enabled, the check will be performed automatically
  336. during the build. The check is run before compilation of the source code.
  337. To speed-up repeated runs of this check, a cache is configured. The cache
  338. is located in the following directory:
  339. output/res/checkstyle
  340. It is possible to run the check separately by calling the "validate"
  341. target. The command is:
  342. cd ${tomcat.source}
  343. ant -Dexecute.validate=true validate
  344. (8.2) FindBugs
  345. NOTE: FindBugs is licensed under LGPL. Using Findbugs during Tomcat build is
  346. optional and is off by default.
  347. See https://spotbugs.github.io/ for more information.
  348. To enable FindBugs, add the following property to build.properties file:
  349. execute.findbugs=true
  350. To compile Tomcat classes and generate a FindBugs report, call the
  351. "findbugs" target. For example:
  352. cd ${tomcat.source}
  353. ant -Dexecute.findbugs=true findbugs
  354. The report file by default is written to
  355. output/findbugs
  356. (8.3) End-of-line conventions check
  357. You usually would not need to run this check. You can skip this section.
  358. Apache Tomcat project has convention that all of its textual source files,
  359. stored in the Git repository, use Unix style LF line endings.
  360. This test is used by developers to check that the source code adheres to
  361. this convention. It verifies that the ends of lines in textual files are
  362. appropriate. The idea is to run this check regularly and notify developers
  363. when an inconsistency is detected.
  364. The command to run this test is:
  365. cd ${tomcat.source}
  366. ant validate-eoln