1. Send Tomcat fork to your own warehouse and download the source code locally
git clone https://github.com/XXX/tomcat.git
2. Install Ant
Tomcat is a project built by ant, so ant needs to be installed. The installation steps are as follows:
(1) Download the installation package (version number at least 1.9.10) (Note: detailed build steps are given on the official website, refer to the link: https://tomcat.apache.org/tomcat-10.0-doc/building.html )
(2) Unzip the installation package apache-ant-1.10.10-bin zip
(3) Edit bash_profile
export ANT_HOME=/Users/sunxi/Documents/application/apache-ant-1.10.10 export PATH=$ANT_HOME/bin:$PATH
(4)source .bash_profile
(5) Verify ant installation
sunxi@sunxideMacBook-Pro ~ % ant -version Apache Ant(TM) version 1.10.10 compiled on April 12 2021
3. Compile Tomcat source code
(1) Copy a build properties. Default file and rename it to build Properties, and modify the base Path (this path is used to store the dependent packages downloaded when building Tomcat. Here is the absolute path)
base.path=/xxx/application/tomcat-build-libs
(2) Will build The following content in the XML file is commented out because it will get an NSIS. XML file when downloading the dependency Exe file, which is used to generate the installation program of tomcat on windows platform. We don't need it here, so we can build it in ant's build file Remove it from the XML. (here, the author has tests before and after the notes, and there are no problems in the author's environment. Here, the author gives a reference link: https://mp.weixin.qq.com/s/iK12Qhj8vcfLLFLPCHwIrg )
<antcall target="downloadzip"> <param name="sourcefile" value="${nsis.loc}"/> <param name="destfile" value="${nsis.exe}"/> <param name="destdir" value="${nsis.home}/.."/> <param name="checksum.enabled" value="${nsis.checksum.enabled}"/> <param name="checksum.algorithm" value="${nsis.checksum.algorithm}"/> <param name="checksum.value" value="${nsis.checksum.value}"/> </antcall>
(3) Execute ant command compilation in the root directory of the source code. After the command is executed successfully, BUILD SUCCESSFUL will be displayed on the screen
The author reported the following errors during compilation. Refer to the link https://blog.csdn.net/u011109679/article/details/117674702 Repaired, specific
The error information and solutions are as follows:
- Error reporting information
BUILD FAILED /Users/sunxi/Documents/gitcode/tomcat/build.xml:1040: The following error occurred while executing this line: /Users/sunxi/Documents/gitcode/tomcat/build.xml:3805: Failed to parse date string 06/15/2021 03:04:19 afternoon.
- resolvent
Put the source code under the root directory build.xml In the file<format property="tstamp.file" pattern="MM/dd/yyyy hh:mm:ss aa"/>Change to <format property="tstamp.file" pattern="123"/>(pattern Modify to any string); Put the source code in the root directory modules/jdbc-pool/build.xml In the file<format property="tstamp.file" pattern="MM/dd/yyyy hh:mm:ss aa"/>Change to <format property="tstamp.file" pattern="123"/>
4. Import the code into IDEA
(1) Execute the following command in the root directory of the source code
ant ide-intellij
After executing the command, the interface will be as follows:
sunxi@bogon tomcat % ant ide-intellij Buildfile: /Users/sunxi/Documents/gitcode/tomcat/build.xml download-bnd: testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/bnd-5.3.0/biz.aQute.bnd-5.3.0.jar setproxy: downloadfile: testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/osgi-annotations-1.0.0/org.osgi.annotation.bundle-1.0.0.jar setproxy: downloadfile: setup-bnd: download-compile: testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/commons-daemon-1.2.4/commons-daemon-1.2.4.jar downloadgz-2: testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/ecj-4.18/ecj-4.18.jar downloadfile-2: testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/jaxrpc-1.1-rc4/geronimo-spec-jaxrpc-1.1-rc4.jar setproxy: downloadfile: testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/wsdl4j-1.6.3/wsdl4j-1.6.3.jar setproxy: downloadfile: testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/migration-1.0.0/jakartaee-migration-1.0.0-shaded.jar setproxy: downloadfile: download-test-compile: testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/junit-4.13/junit-4.13.jar setproxy: downloadfile: [get] Getting: https://repo.maven.apache.org/maven2/junit/junit/4.13/junit-4.13.jar [get] To: /Users/sunxi/Documents/application/tomcat-build-libs/download-1854922165.tmp [echo] Checksum check for junit-4.13.jar, algorithm MD5|SHA-1: OK [mkdir] Created dir: /Users/sunxi/Documents/application/tomcat-build-libs/junit-4.13 [move] Moving 1 file to /Users/sunxi/Documents/application/tomcat-build-libs/junit-4.13 testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/hamcrest-2.2/hamcrest-2.2.jar setproxy: downloadfile: [get] Getting: https://repo.maven.apache.org/maven2/org/hamcrest/hamcrest/2.2/hamcrest-2.2.jar [get] To: /Users/sunxi/Documents/application/tomcat-build-libs/download-220608314.tmp [echo] Checksum check for hamcrest-2.2.jar, algorithm SHA-512: OK [mkdir] Created dir: /Users/sunxi/Documents/application/tomcat-build-libs/hamcrest-2.2 [move] Moving 1 file to /Users/sunxi/Documents/application/tomcat-build-libs/hamcrest-2.2 testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/easymock-4.2/easymock-4.2.jar setproxy: downloadfile: [get] Getting: https://repo.maven.apache.org/maven2/org/easymock/easymock/4.2/easymock-4.2.jar [get] To: /Users/sunxi/Documents/application/tomcat-build-libs/download-989123826.tmp [echo] Checksum check for easymock-4.2.jar, algorithm SHA-512: OK [mkdir] Created dir: /Users/sunxi/Documents/application/tomcat-build-libs/easymock-4.2 [move] Moving 1 file to /Users/sunxi/Documents/application/tomcat-build-libs/easymock-4.2 testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/cglib-3.3.0/cglib-nodep-3.3.0.jar setproxy: downloadfile: [get] Getting: https://repo.maven.apache.org/maven2/cglib/cglib-nodep/3.3.0/cglib-nodep-3.3.0.jar [get] To: /Users/sunxi/Documents/application/tomcat-build-libs/download-1431192676.tmp [echo] Checksum check for cglib-nodep-3.3.0.jar, algorithm SHA-512: OK [mkdir] Created dir: /Users/sunxi/Documents/application/tomcat-build-libs/cglib-3.3.0 [move] Moving 1 file to /Users/sunxi/Documents/application/tomcat-build-libs/cglib-3.3.0 testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/objenesis-3.1/objenesis-3.1.jar setproxy: downloadfile: [get] Getting: https://repo.maven.apache.org/maven2/org/objenesis/objenesis/3.1/objenesis-3.1.jar [get] To: /Users/sunxi/Documents/application/tomcat-build-libs/download-945284156.tmp [echo] Checksum check for objenesis-3.1.jar, algorithm SHA-512: OK [mkdir] Created dir: /Users/sunxi/Documents/application/tomcat-build-libs/objenesis-3.1 [move] Moving 1 file to /Users/sunxi/Documents/application/tomcat-build-libs/objenesis-3.1 testexist: [echo] Testing for /Users/sunxi/Documents/application/tomcat-build-libs/unboundid-5.1.4/unboundid-ldapsdk-5.1.4.jar setproxy: downloadfile: [get] Getting: https://repo.maven.apache.org/maven2/com/unboundid/unboundid-ldapsdk/5.1.4/unboundid-ldapsdk-5.1.4.jar [get] To: /Users/sunxi/Documents/application/tomcat-build-libs/download-1631250359.tmp [echo] Checksum check for unboundid-ldapsdk-5.1.4.jar, algorithm SHA-512: OK [mkdir] Created dir: /Users/sunxi/Documents/application/tomcat-build-libs/unboundid-5.1.4 [move] Moving 1 file to /Users/sunxi/Documents/application/tomcat-build-libs/unboundid-5.1.4 ide-intellij: [copy] Copying 10 files to /Users/sunxi/Documents/gitcode/tomcat/.idea [echo] IntelliJ IDEA project directory created. Please create PATH VARIABLES for [echo] [echo] ANT_HOME = /Users/sunxi/Documents/application/apache-ant-1.10.10 [echo] TOMCAT_BUILD_LIBS = /Users/sunxi/Documents/application/tomcat-build-libs [echo] BUILD SUCCESSFUL Total time: 1 minute 1 second
(2) Import the code into IDEA and configure ant in IDEA_ Home and TOMCAT_BUILD_LIBS, as shown in the figure below:
(3) Create a Catalina home directory locally and copy all files in the build directory under the output directory of the compiled source code to Catalina home
(4) Configure Tomcat's entry and VM parameters in IDEA, as follows:
Configuration item | value |
---|---|
Main class | org.apache.catalina.startup.Bootstrap |
VM options | -Dcatalina.home=/Users/sunxi/Documents/application/catalina-home -Duser.language=en -Duser.region=US -Dfile.encoding=UTF-8 |
5. Start Tomcat in IDEA
The startup method is to run org apache. catalina. startup. After bootstrap's main method is started, open the browser and enter 127.0.0.1:8080. The page is displayed as follows: