Tomcat is a familiar web server and is open-source. This article describes how to run the source code project of tomcat in eclipse. The Tomcat Source Code involved in this article takes Tomcat 6. x as an example.
1. Get tomcat source code
You can obtain the Tomcat source code in either of the following ways:
(1) download the source code package directly. For details, see http://tomcat.apache.org/download-60.cgi.Source code Distributions
(2) Use SVN to obtain the source code. The SVN root path is http://svn.apache.org/repos/asf/tomcat/use tortoisesvn.
2. Obtain the source code dependency package
Tomcat 6.x is compiled using ant. The simplest way to obtain the Tomcat 6.x source code dependency package is to use ant to directly obtain
(1) install ant at http://ant.apache.org/bindownload.cgito download the latest ant package and decompress it.
Set environment variables:
Step 1: java_home: JDK installation path
Step 2: ant_home: ant installation path
Step 3: Add "; % ant_home % \ bin" to the path"
Switch to the Windows Command window and enter ant-help. If ant is selected, the installation is successful.
(2) download the Tomcat 6. x source code dependency package
Step 1: In the Tomcat 6. x source code path, find build. properties. Default and open it in a text editor.
Add # comment out before base. Path =/usr/share/Java
Remove # At the beginning of the line # base. Path = C:/path/to/The/Repository. This path is the path of the Tomcat dependency package to be downloaded, which can be modified. :
Step 2: switch to the Tomcat source code path in the Windows Command window
Enter ant download to automatically download
Step 3: After downloading the dependent package, enter the ant command to compile the source code.
After compilation, we have prepared the Tomcat source code and its dependent packages.
3. Run the Tomcat project in eclipse.
There are two files in the Tomcat 6. x source code path: Eclipse. classpath and eclispe. Project.
Rename these two files to. classpath and. Project. If you cannot rename a file in Windows, you can use the Ren command in command line mode.
Open eclipse and add the following variables to Windows> preferences> JAVA> build path> classpath variables:
Ant_home: ant installation path
Tomcat_libs_base: Path of the Tomcat dependency package.
For example:
In this case, everything is ready. You only need to import the exist project.
4. Tomcat running
Right-click the project and click Run .....
Go to run configurations.
Create a running configuration named Catalina
Main class selection:
Org. Apache. Catalina. startup. Catalina
Switch to the arguments Tab
Enter start in program arguments.
In VM arguments, enter-dcatalina. Home = source code path.
Finally, click Run to run the Tomcat source code.