编译并运行Tomcat9

准备工作

下载最新版的Tomcat、ant、maven,官网下载即可
Tomcat要下载源码包,不要下载二进制文件

配置ant环境变量

此处直接盗用网络上的配置图
在这里插入图片描述

通过ant下载包

打开cmd窗口,跳转至Tomcat源码包根路径,即包含有build.xml的目录,执行ant命令,等待命令结束,会在output\build目录中生成启动Tomcat所需的文件

创建catalina-home

在源码包同级目录创建catalina-home,将源码包中output\build目录中所有文件复制到catalina-home中,该文件中是Tomcat启动所必需的的文件

要开始跑了

1、idea打开包含源码包和catalina-home的目录,如下图设置source folders和excluded folders
在这里插入图片描述
2、导入jar或配置maven管理jar,此处使用maven管理jar,配置如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<groupId>org.apache.tomcat</groupId>
	<artifactId>Tomcat9</artifactId>
	<name>Tomcat9</name>
	<version>9.0</version>

	<build>
		<finalName>Tomcat9.0</finalName>
		<sourceDirectory>java</sourceDirectory>
		<!--<testSourceDirectory>test</testSourceDirectory>-->
		<resources>
			<resource>
				<directory>java</directory>
			</resource>
		</resources>
		<outputDirectory>output/classes</outputDirectory>
		<!--<testResources>-->
		<!--<testResource>-->
		<!--<directory>test</directory>-->
		<!--</testResource>-->
		<!--</testResources>-->
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<encoding>UTF-8</encoding>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>org.easymock</groupId>
			<artifactId>easymock</artifactId>
			<version>3.4</version>
		</dependency>
		<dependency>
			<groupId>ant</groupId>
			<artifactId>ant</artifactId>
			<version>1.7.0</version>
		</dependency>
		<dependency>
			<groupId>wsdl4j</groupId>
			<artifactId>wsdl4j</artifactId>
			<version>1.6.2</version>
		</dependency>
		<dependency>
			<groupId>javax.xml</groupId>
			<artifactId>jaxrpc</artifactId>
			<version>1.1</version>
		</dependency>
		<dependency>
			<groupId>org.eclipse.jdt.core.compiler</groupId>
			<artifactId>ecj</artifactId>
			<version>4.5.1</version>
		</dependency>
	</dependencies>
</project>

此处会有个问题,maven会修改excluded folders,所以在pom文件中添加了如下配置。

<build>
	<outputDirectory>output/classes</outputDirectory>
</build>

如果仍有问题,手动将target的excluded标识去掉
在这里插入图片描述
3、配置Bootstrap启动
main class:

org.apache.catalina.startup.Bootstrap

VM option参数:

-Dcatalina.home="F:\ybtrefact\Tomcat9\catalina-home"

4、ok,正常启动。此处不需要idea或maven编译了,执行ant命令下载jar时已经编译好了,直接运行就好了
5、如果没有正常运行,报错NoDefClassFound 或加载不到主类,请按照上述步骤重新走一遍,不行就多走几遍。

详细可参考https://www.jianshu.com/p/42df9d545e88
https://www.jb51.net/article/144696.htm两篇文章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

91老码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值