Tomcat source code learning (1) Source code compilation and import eclipse

Source: Internet
Author: User
Original works can be reprinted. During reprinting, you must mark the original source, author information, and this statement in hyperlink form. Otherwise, legal liability will be held. Http://panpan.blog.51cto.com/489034/120826

Because the current project is relatively easy, and the project is studying SOA and Web Service, I want to do some research on some related open-source technologies. Next I will write an article about the Tomcat source code series. Article (1) describes how to compile the Tomcat source code and import the Tomcat project to S. Here I will share my compilation experience.
Everyone knows that Java's open-source projects are very powerful. It is these open-source projects that promote the progress of a large number of outstanding programmers and the rapid development of software. There are a lot of programmers who have read and viewed open-source projects, but there are not many developers who actually participate in them. In fact, our development capabilities will be greatly enhanced only when we are truly involved in open-source projects, and our developers will be better at software management, our software industry will also grow stronger.
I think we can describe open-source software by building a harmonious society, that is, co-building in sharing and sharing in co-building. Well, if we don't talk so much about it, we will start our tomcat source code journey.

1. Download Tomcat source code

Please first from the [url] http://subversion.tigris.org/servlets/ProjectDocumentList? Folderid = 91 [/url] download the license control tool subversion. the downloaded file is svn-win32-1.5.4.zip. decompress the package and put the bin path under the Environment Variable path. You can use this version control tool.
In the MS-DOS window, enter: SVN export [url] into F: \ project \ Tomcat \ apache-tomcat-6.0.18-src \ here I put the source code to be downloaded to this directory of drive F. Tomcat_6_0_18 is the latest source code version.
This directory displays the Tomcat source code directory. The output directory and eclipse_output directory do not exist. This is the directory generated after compilation. Therefore, you must note that.

2. Compile and run

Use ant tool for code compilation. Download the ant tool from [url] http://ant.apache.org/bindownload.cgi#/url. I downloaded apache-ant-1.7.1-bin.zip, decompress the package, and put the bin path under the Environment Variable path.
Rename the build. properties. default file in this directory to build. properties. Open build. properties, find Base. Path =/usr/share/Java, and change base. Path = F:/project/share. This directory in drive F is my local directory. You can set an existing directory on your computer.
During Tomcat compilation, ant will let us download some necessary dependent projects, base. the path directory is used to save these project files. We can point this attribute to an existing Directory. After modifying base. Path, go back to the MS-DOS window, switch to the directory where Tomcat source code is located, and run the ant download Command, as shown in:

This time we waited for a long time, because eclipse-jdt-3.2.zip was about 20 mb, And the download took some time. After a period of time, the compiler may give several warnings. At this time, we can find that six dependent projects have been downloaded from the base. Path directory (F:/project/share) just created, which are required for Tomcat compilation.
Now let's start the real compilation task. Type ant in the MS-DOS window and press Enter. Ant will compile more than 1000 source files within 2 minutes and deploy tomcat to the output directory. After compilation is complete, open the source code directory of Tomcat and you will find that an output directory is added, which is the output directory after ant compilation. Open the output \ build \ bin subdirectory of Tomcat source code and double-click STARTUP. BAT file, we can successfully start tomcat6.0, if not, please pay attention to set the environment variable catalina_home, set to F: \ project \ Tomcat \ apache-tomcat-6.0.18-src \ output \ build. At this time, our compilation work is successfully completed.
The following error may occur:
(1) An error occurred while executing the ant download command, probably because the line jdt. Loc = http://www.eclipse.org/downloads/download.php In the build. properties file could not be found? File =/Eclipse/downloads/drops/R-3.3.1-200709211145/eclipse-JDT-3.3.1.zip this package, readers search for this package on the Internet, the Web site for a change. However, I use the latest version, which is available at least for a period of time.
(2) There are many causes of errors when executing the ant command. The following error occurs:

[Javac] D: \ Tomcat \ share \ tomcat6-deps \ DBCP \ SRC \ Java \ org \ apache \ Tomcat \ DBCP \ DB
CP \ basicdatasource. Java: 43: org. Apache. tomcat. DBCP. DBCP. basicdatasource is not abstract
And does not overwrite the abstract method iswrapperfor (Java. Lang. Class <?>) in Java. SQL. wrapper)
[Javac] public class basicdatasource implements datasource {
[Javac] ^
[Javac] D: \ Tomcat \ share \ tomcat6-deps \ DBCP \ SRC \ Java \ org \ apache \ Tomcat \ DBCP \ DB
CP \ delegatingstatement. Java: 45: org. Apache. tomcat. DBCP. DBCP. delegatingstatement
It is not abstract and does not overwrite the abstract method ispoolable () in Java. SQL. Statement ()

There are a lot of errors. This is because the JDK version I use is 1.6, so this problem occurs. Replace JDK with 1.5 and java_home with JDK 1.5, these errors are solved. There are still some warnings, but it does not matter.

If you have other errors or problems during compilation, leave a message to contact me.

3. Import the source code to eclipse

(1) Open eclipse, create a Java project, select "Create project from existing source", and import the existing Code project, as shown in:

Click "finish" to create the project.
(2) After the import is complete, some error messages will be displayed. Right-click the project tomcat, select "build path"-> config build path, delete two libraries starting with tomcat_libs, and retain the JRE library and JUnit library.
(3) set ant. jar (Lib in the ant file downloaded) and org. eclipse. jdt. core_3.3.1.v_780_r33x.jar (included in F: \ project \ share) is copied to the Lib folder under the Code project (not included in the Lib folder before, and needs to be created manually ). Select "Config build path"-> "add library", add a user library, add the two jar packages, and name them tomcat_lib. In the latest version of Tomcat 6.0.18, there are two. java code file: serviceproxy. java and servicereffacloud. some classes in other packages are used in Java, such as import javax. XML. RPC. service and import plugin, is: [url] http://apache.freelamp.com/ws/axis/1_4/axis-bin-1_4.zip [/url] After decompression in the lib directory can see the two jar packages, directly add to the project.
After adding, as shown in:

(4) Run Tomcat: Find the main startup class Org. apache. catalina. in the startup package, right-click the bootstrap class and choose "Run as"> "run events". In the arguments window, make the following settings:
Write: Start in program arguments
Write:-dcatalina. Home = "F: \ project \ Tomcat \ apache-tomcat-6.0.18-src \ output \ build" in VM arguments ". As shown in:

Run tomcat, as shown in:

(5) Stop Tomcat: As in the preceding step, write: Stop in program arguments and click Run. You can stop tomcat.

4. Summary

So far, the two methods of compiling Tomcat source code and importing eclipse have been completed. Here, the reason why we import them to eclipse is to facilitate code reading, and we can also perform a single step on the code, it makes sense to look at the code execution process. Well, the next task is to go deep into the Code. This is an exciting thing, because Tomcat is a very good project, and its code is also tempting. No, I began to appreciate the code. later articles will share the code details with you, and I will also discuss the Code with interested readers. Because the project is relatively large and far exceeds 2 MB, I will not upload it. Readers who need it can leave a message and I will send it to you.

This article is from the "C ++ technology" blog, please be sure to keep this source http://panpan.blog.51cto.com/489034/120826

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.