Linux source code and compiled Tomcat9 import IDEA

Tomcat is used ant management, you can also write files into a pom maven way.

First, download the Ant

Since it is constructed with ant management, it would have to install ant, address: https: //ant.apache.org/bindownload.cgi
After downloading, you need to put him in the system PATH (JAVA installation mode).
gedit /etc/profile
export ANT_HOME=ant路径
export PATH=$ANT_HOME/bin:$PATH
source /etc/profile
Here Insert Picture Description
If the installation is successful, enter ant -version can see the ant version
Here Insert Picture Description

Second, download Tomcat9

Address: https: //tomcat.apache.org/download-90.cgi
then click to download the source code, one of two formats will do.
Here Insert Picture Description
Unzip into the directory tomcat, due to the tomcat rely on other jar, when the building will automatically download, download path can be configured in build.properties.default in about 89 lines there base.path, can not be modified, the default is $ {user.home} / tomcat-build- libs.
Here Insert Picture Description
Here Insert Picture Description

Three, ant build

直接输入ant即可开始构建,这个过程中会下载依赖的jar,但是他不显示进度,可以到他的依赖jar下载目录,一直刷新查看他当前下载的文件大小。
Here Insert Picture Description
比如这里正在下载wsdl4j-1.6.3.jar,临时存放到了/home/hxl/tomcat-build-libs/download-1686272198.tmp,去这个文件中不停看他的大小,如果长时间不动,就得换个网试试了。
Here Insert Picture Description
或者手动下载,比如他先会输出testexist,判断这个jar是否存在,如果存在,则不下载。当手动下载好一个jar后,新建一个这个jar所在的文件夹,就是以下红色圈住的,把这个jar放入进入(更具不同jar而定)。重新ant以下,就好了。
Here Insert Picture Description
当所有jar都下载好之后,剩下的工作一气呵成,经过ant噼里啪啦的一顿构建复制,会在其目录output/build下生成构建好的tomcat,这个目录就是我们常用的,进入bin可以直接./startup.sh启动Tomcat
Here Insert Picture Description
Here Insert Picture Description

四、Bootstrap

tomcat的启动类在java/org/apache/catalina/startup/Bootstrap.java中,编译后在bin/bootstrap.jar中,如果单纯的java -jar bootstrap.jar指定是启动不了的。因为有些依赖他不知道,所以需要catalina.sh来给他传入。catalina中指定了很多VM参数,如-classpath。下面的这段其中还向Bootstrap传入了start,Bootstrap会在main方法中进行判断。
Here Insert Picture Description
Here Insert Picture Description

五、IDEA 导入源码

Direct File-Open-Tomcat source code can be.
Here Insert Picture Description
Then open the project settings, specify a compiler output directory.
Here Insert Picture Description
Finally, the java folder to identify the source of it.
Here Insert Picture Description
But when the building will complain, one missing jar package, the second is the default under webapps project lead.
It is also very simple to solve, first create a lib folder, to download the above jar package are copied to here, then all selected, right-click the Add as Library can be. Webapps and delete all the files.

Then find the startup class, right-click to start
Here Insert Picture Description
if nothing else like this. This time we can put it war under webapps, debug, and learning.
Here Insert Picture Description

Published 42 original articles · won praise 7 · views 7714

Guess you like

Origin blog.csdn.net/HouXinLin_CSDN/article/details/104475354