If you want to study the architecture or source code of Tomcat, it is best to import the source code of Tomcat to the IDE and compile the instance for code tracking (Debug ).
Here, I have referred to some online materials and recorded my operation process as a flow account.
Preparation:
1. Download Tomcat source code
Download the tomcat-6.0.33 source code.
2. Install ant to compile the Tomcat source code.
Download and decompress ant and add its bin to the system environment path.
3. ide -- select eclipse3.7.
======================================
Step 1:
Decompress the Tomcat source code, suchD: \ Tomcat \ apache-tomcat-6.0.33-src..
Step 2:
2.1) Use ant to compile Tomcat source code. Before compilation, You need to download relevant dependent projects. What should we do if we do not know which dependencies are required for compilation?
Let ant help! We only need to prepare a place to store these dependent projects, suchD: \ Tomcat \ basepath.
2.2) to make ant work, we also need to rename build. properties. default in the apache-tomcat-6.0.33-src folder to build. properties,
Open it and modifyBase. Path = D: \ Tomcat \ basepath.
2.3) download the dependent project, go to the command console, and enter the DirectoryD: \ Tomcat \ apache-tomcat-6.0.33-src., Run the following command:Ant download.
2.4) after the dependent project is downloaded, You can compile tomcat. Run the following command:Ant. After compilation, we can view the DirectoryD: \ Tomcat \ apache-tomcat-6.0.33-src.,
A folder is added to the folder:Output.
The output folder structure is as follows:
We will find that this structure is consistent with the Tomcat structure extracted from the installation package.
Go to bin and start Tomcat. It indicates that -- ant has compiled tomcat!
============================================
Import Tomcat source code to eclipse.
Step 1:
Create a Java project in eclipse, for example, tomcat6.
Step 2:
Import-> File System
Select Tomcat source code in from directory and Java and test (select test if you need to test), for example:
In into folder, select tomcat6 and finish.
Note: Set Java and test to source folder, Java build path-> source-> Add folder...-> select Java and test.
Shows the current project structure:
Part 3: import the jar package.
The above unpleasant Red Cross is due to the lack of jar. What jar packages do we need now?
Test requires JUnit. jar, which can be directly used in eclipse.
Java requires:
- Ant. Jar
- Jaxrpc. Jar
- Org. Eclipse. jdt. core_3.3.1.v_780_r33x.jar
- Wsdl4j-1.5.1.jar
After the import, it will be refreshed!
Step 4:
Start tomcat in eclipse.
Find the bootstrap class in the org. Apache. Catalina. startup package.
Run as: Set in the VM arguments of arguments
-Dcatalina. Home = "D: \ output \ build"
Then you can start it!
========================================================== =
Problem:
Why do I need to set-dcatalina. Home = "D: \ output \ build "?
First, describe what output is-it is the Output Folder compiled by Ant. You can try to delete the content to see if it can be started successfully.
What happens if this parameter is not configured? Delete-dcatalina. Home = "D: \ output \ build" with the following error:
2011-10-20 14:49:35 org. Apache. Catalina. startup. classloaderfactory validatefile
Warning Problem with directory [D: \ myworkspace \ tomcat6 \ Lib], exists: [false], isdirectory: [false], Canread: [false]
2011-10-20 14:49:35 org. Apache. Catalina. startup. classloaderfactory validatefile
Warning Problem with directory [D: \ myworkspace \ tomcat6 \ Lib], exists: [false], isdirectory: [false], Canread: [false]
2011-10-20 14:49:35 org. Apache. Catalina. startup. Catalina Load
Warning: Can't load server. XML from D: \ myworkspace \ tomcat6 \ conf \ Server. xml
2011-10-20 14:49:35 org. Apache. Catalina. startup. Catalina Load
Warning: Can't load server. XML from D: \ myworkspace \ tomcat6 \ conf \ Server. xml
2011-10-20 14:49:35 org. Apache. Catalina. startup. Catalina start
Severe: cannot start server. server instance is not configured.
It can be seen that there is no lib folder under the root directory of the project, no conf folder, and no server. XML in the conf file, so the server cannot be instantiated.
Then follow the prompts and start it!