Tomcat 8 source code compilation and import Eclipse research

Source: Internet
Author: User
Tags file system microsoft sql server pack tomcat apache tomcat

Recently because of the need to modify tomcat some of the features, but can only study that part of the source code and then slightly modified.

Currently, the latest Tomcat version is 8.0, download the source package, compile and import eclipse in the study is more convenient.

1. Tomcat8 source Code compilation step 1.1 first to Apache Tomcat 8.0 website Download the latest version of the source Code distributions, extract to a directory, such as D:\apache-tomcat-8.0.5-src

1.2 Using ant to compile

(1) Install Ant

If you've installed Ant on the machine to omit this step, go to Ant's website to download the latest version of Ant Binary Distributions, extract it into a directory, such as D:\Program files\apache-ant-1.9.3, and then configure the environment variables. Either create a new ant_home, the value is an ant path, and then add the ant bin path to%ant_home%/bin in path, or add the ant bin path to D:\Program directly in path files\apache-ant-1.9.3\ Bin When configured, run ant-version under CMD, and if the display version description is successful, we can use ant anywhere.

(2) Compile Tomcat 8.0

Very simple, cmd into the newly downloaded source path, with the following two commands can be compiled:

Ant Download

The ant "Ant download" command downloads the dependent packages required to compile Tomcat.

Here are two questions to note:

Where does the dependency pack download? Under Linux or Macox, the default download to the "/usr/share/java" directory is, of course, that ordinary users do not have permission to write; under Windows, default downloads to "a disk: \usr\share\java", which may be C, D, or other, This generally depends on which disk you put the Tomcat source on, such as mine in D, which is downloaded by default under "D:\usr\share\java". What if I want to define the download path myself?

If the user is the Internet through the agent, then the download process will be wrong. How to solve?

People who are familiar with ant should know how to fix it, by configuring the file Build.properties to set it up. The profile is "Build.properties.default" under the Tomcat source path, and we can remove the. default suffix or create a new build.properties directly, of course I chose the former, will " Build.properties.default "modified to" build.properties "open, modify the Base.path attribute values in the desired download path and add proxy proxy configuration, in the following format:

#-----Proxy Setup-----

# Uncomment if using a proxy server

Proxy.host=proxy.domain

proxy.port=8080

Proxy.use=on

#-----Default Base Path for Dependent Packages-----

# Replace This path with the directory path where dependencies binaries

# should be downloaded

Base.path=/home/me/some-place-to-download-to set According to your needs, and note that if you don't need a setting, you need to use the # annotation.

After the success of the package download (if the download failed to try more than a few times), execute ant to compile, after the successful compilation of the current path next more output folder, is our compilation results.

Report:

① If you modify some of the source code, you need to recompile, go directly to the source path, execute ant command.

② If you need to compile the servlet and JSP API documentation, go to the source path and execute the following command:

Ant-f Dist.xml Dist-javadoc③ If you need to compile extras extensions (commons-logging, webservices etc.), go to the source path to execute the following command:

Ant-f Extras.xml④ If you need to compile the release version, go to the source path to execute the following command:

Ant-f Dist.xml Release

2. Import Tomcat source into Eclipse research because Tomcat is not an eclipse-managed project and cannot be imported directly, you need to create a new Java project, such as TOMCAT8, where you can import the source code in two different ways.

First: Copy the required source Pack Java and test (junit test case, optional) two folders directly to SRC.

Second: Select File-> Import-> file System, select Java and test two folders in the Tomcat package in from directory, and select the TOMCAT8 project we just created in into folder. Finish, and then remember to mark the two folders as source code (how do you mark them?) Right-click Selector folder-> build Path-> use as Source folder).

Of course, after this is not finished, you will find the whole project a lot of Red fork, that is, the lack of dependency on the package, in the build path, add the following several dependencies:

Java packages require the following four jar packages, note that the version may be different:

Ant.jar

Jaxrpc.jar

Org.eclipse.jdt.core_3.8.3.v20130121-145325.jar

Wsdl4j-1.5.1.jartest bag needs Junit.jar, direct "ADD libraries ..." Choose JUnit:

Junit.jar Of course you can also start Tomcat in eclipse by doing the following:

Find class: Org.apache.catalina.startup.Bootstrap.java, can also be seen from the name of the startup class, if you run the class directly at this time, you will report the following error:

APR, 2014 3:27:38 PM org.apache.catalina.startup.ClassLoaderFactory validatefile

Warning:problem with directory [D:\workspace\Tomcat8\lib], exists: [false], isdirectory: [false], CanRead: [FALSE]

APR, 2014 3:27:38 PM org.apache.catalina.startup.ClassLoaderFactory validatefile

Warning:problem with directory [D:\workspace\Tomcat8\lib], exists: [false], isdirectory: [false], CanRead: [FALSE]

APR, 2014 3:27:40 PM Org.apache.catalina.startup.Catalina load

Warning:can ' t load server.xml from D:\workspace\Tomcat8\conf\server.xml

APR, 2014 3:27:40 PM Org.apache.catalina.startup.Catalina load

Warning:can ' t load server.xml from D:\workspace\Tomcat8\conf\server.xml

APR, 2014 3:27:40 PM Org.apache.catalina.startup.Catalina start

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/Java/

Severe:cannot start server. Server instance is not Configured. said there is no server instance configured, from the warning statement can know the reason: the current project path does not have Lib and Conf folder, so that the server configuration file Server.xml cannot be found, of course, can not instantiate the server.

There are two solutions:

① copy these two folders directly to project engineering

So where are the two folders? Go to the Tomcat source path we can see only the Conf configuration folder does not have a Lib folder, in fact this is the reason I compiled Tomcat: Lib in the compiled output folder in the Build folder, Conf here also. Of course, you can also download the binary package directly from the official website, which is a compiled tomcat, the root path has these two folders. Copy the Conf and Lib folders below the build directly into the project, run again, and start successfully.

APR, 2014 3:37:58 PM org.apache.catalina.core.AprLifecycleListener Init

Info:the APR based Apache Tomcat Native Library which allows optimal performance in production environments is not found On the Java.library.path:d:\program files\java\jre7\bin; C:\Windows\Sun\Java\bin; C:\Windows\system32; C:\Windows; C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\;D: \program Files\tortoisegit\bin; C:\Program Files (x86) \ Windows Kits\8.1\windows performance toolkit\; C:\Program Files\Microsoft SQL server\110\tools\binn\;D: \program Files\gow\bin;d:\program Files\Visual Leak Detector\ Bin\win32;d:\program files\visual leak Detector\bin\win64;d:\program Files\java\jdk1.7.0_51\\bin;d:\program Files\ Apache-maven-3.2.1\bin;d:\program Files\git\cmd;

APR, 2014 3:38:00 PM org.apache.coyote.http11.Http11Protocol Init

Info:initializing Coyote http/1.1 on http-8080

APR, 2014 3:38:00 PM Org.apache.catalina.startup.Catalina load

Info:initialization processed in 2254 ms

APR, 2014 3:38:00 PM org.apache.catalina.core.StandardService start

Info:starting Service Catalina

APR, 2014 3:38:00 PM org.apache.catalina.core.StandardEngine start

Info:starting Servlet engine:apache tomcat/@VERSION @

APR, 2014 3:38:00 PM org.apache.coyote.http11.Http11Protocol start

Info:starting Coyote http/1.1 on http-8080

APR, 2014 3:38:00 PM org.apache.jk.common.ChannelSocket Init

INFO:JK:AJP13 Listening on/0.0.0.0:8009

APR, 2014 3:38:00 PM org.apache.jk.server.JkMain start

INFO:JK running Id=0 time=0/29 config=null

APR, 2014 3:38:00 PM Org.apache.catalina.startup.Catalina start

Info:server Startup in 386 Ms② Add VM virtual machine run parameters

The second method is to add the VM parameters, specify the specific path of the two folders, and use the VM's-D parameter to specify the Catalina.home property value as the specific path, as follows:

Run as-> run Configuration ...-> Arguments-> VM Arguments set:

-dcatalina.home= "D:/apache-tomcat-8.0.5-src/output/build"

And then run is ready to start.

Author: cnblogs Alexia (Minmin)

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.