JDK和Tomcat下载和配置
- 实际测试版本
jdk1.8.0_351
apache-tomcat-8.5.100
疑问解答
- 为什么配置环境变量?
- 因为运行是需要有依赖库或者执行文件,tomcat要依赖java环境
- JAVA_HOME 是在tomcat中要有这个环境变量
- CATALINA_HOME 也是tomcat自己要用
JDK环境配置
JDK下载
https://www.oracle.com/cn/java/technologies/downloads/
备注:JDK8往页面最后翻可以找到
JAVA_HOME
新建JAVA_HOME
变量名:JAVA_HOME
变量值:C:\Program Files\Java\jdk1.8.0_351
新建CLASSPATH
变量名:CLASSPATH
变量值:.;%JAVA_HOME%\lib
增加PATH
增加内容:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin
测试JDK配置
- 查看java和javac的版本信息
C:\Users>java -version
java version "1.8.0_351"
Java(TM) SE Runtime Environment (build 1.8.0_351-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.351-b10, mixed mode)
C:\Users>javac -version
javac 1.8.0_351
Tomcat环境配置
Tomcat下载
https://tomcat.apache.org/download-80.cgi
CATALINA_HOME
新建CATALINA_HOME
变量名:CATALINA_HOME
变量值:D:\tools\apache-tomcat-8.5.100
增加PATH
增加内容:%CATALINA_HOME%\bin
log乱码
- 修改编码格式 apache-tomcat-8.5.100\conf\logging.properties
java.util.logging.ConsoleHandler.encoding = GBK
端口号修改
- tomcat默认端口号是8080,如果想修改默认端口号可修改文件:apache-tomcat-8.5.100\conf\server.xml 将8080修改为8888
<Connector port="8888" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxParameterCount="1000"
/>
异常处理
- JDK与Tomat版本不匹配会导致Tomat启动一闪而过
Apache Tomcat Version | Supported Java Versions |
---|---|
:10.0.x (superseded) | : 8 and later |
:8.5.x (EOL) | : 7 and later |
:8.0.x (superseded) | : 7 and later |
:7.0.x (archived) | : 6 and later(7 and later for WebSocket) |
:6.0.x (archived) | : 5 and later |
:5.5.x (archived) | : 1.4 and later |
:4.1.x (archived) | : 1.3 and later |
:3.3.x (archived) | : 1.1 and later |
tomcat运行&停止
- 运行,控制台执行以下指令
startup.bat # 该文件的目录是在apache-tomcat-8.5.100\bin
- 停止,控制台执行以下指令
shutdown.bat # 该文件的目录是在apache-tomcat-8.5.100\bin