Tomcat容器学习笔记

1.基本概念

context:在tomcat中相当于一个web 应用。

2.关键目录和文件

  • /bin - Startup, shutdown, and other scripts. The *.sh files (for Unix systems) are functional duplicates of the *.bat files (for Windows systems). Since the Win32 command-line lacks certain functionality, there are some additional files in here. 启动停止和其他的脚本。sh文件(unix系统)在功能上和bat文件(windows系统)是重复的。因为win32系统命令行缺少某些功能,这里会有额外的一些文件。
  • /conf - Configuration files and related DTDs. The most important file in here is server.xml. It is the main configuration file for the container.
  •  配置文件和相关的DTD(document type difinition).最重要的文件是server.xml.它是容器的主要配置文件。
  • /logs - Log files are here by default. 默认的日志文件夹。
  • /webapps - This is where your webapps go 放置web应用的地方。
  • /work - tomcat的工作运行目录,每个catalina_base(tomcat运行实例)下都会有work目录存放web容器处理后的jsp文件(转为java文件并编译生成class文件)详情可看JavaWeb-Jsp部分。

 

3.重要属性:

  • CATALINA_HOME: Represents the root of your Tomcat installation, for example /home/tomcat/apache-tomcat-9.0.10 or C:\Program Files\apache-tomcat-9.0.10.
  • CATALINA_BASE: Represents the root of a runtime configuration of a specific Tomcat instance. If you want to have multiple Tomcat instances on one machine, use the CATALINA_BASE property.

CATALINA_BASE 可以在你想要在一台机器上运行多个tomcat实例时进行设置。

 

4.tomcat安装配置步骤

1.Download and Install a Java SE Runtime Environment (JRE)

2.Download and Install Apache Tomcat

3.Configure Environment Variables

    Tomcat is a Java application and does not use environment variables directly. Environment variables are used by the Tomcat startup scripts. The scripts use the environment variables        to prepare the command that starts Tomcat.The Tomcat startup scripts have some logic to set this variable automatically if it is absent, based on the location of the startup script in *nix and on the current directory in Windows. That logic might not work in all circumstances, so setting the variable explicitly is recommended.

   tomcat shi一个java应用并不直接使用环境变量。环境变量被tomcat的启动脚本使用。这些脚本用环境变量去准备tomcat启动命令。tomcat启动脚本在这些环境变量不存在时可以自动进行设置,在linux系统里依赖于启动脚本所在的位置,在window系统是当前目录。启动脚本设置环境变量的逻辑可能不适用所有情况,因此推荐显式设置这些变量。

     (3.1) Set CATALINA_HOME (required) and CATALINA_BASE (optional) 因为CATALINA_BASE默认和CATALINA_HOME一致。

     (3.2) Set JRE_HOME or JAVA_HOME (required)

 4.Start Up Tomcat

 

5.部署启动顺序:

当不使用Tomcat Manager 或者TCD(Tomcat Client Deployer)时tomcat启动顺序如下:

1.Context Descriptors will be deployed first. 应用描述文件会被最先部署。

2.Exploded web applications not referenced by any Context Descriptor will then be deployed. If they have an associated .WAR file in the appBase and it is newer than the exploded web application, the exploded directory will be removed and the webapp will be redeployed from the .WAR

没有关联 应用描述文件的应用文件夹会被部署。如果这些文件夹有关联位于appBase(default appBase is "$CATALINA_BASE/webapps)下的.war文件并且war文件比文件夹下的web应用要新,那么文件夹会被移除,.war文件会被部署。

3.WAR files will be deployed

 

6.tomcat在IDEA中的配置

tomcat版本:

Apache Tomcat/10.0.6

IDEA版本:

IntelliJ IDEA 2021.1.1 (Ultimate Edition)
遇到的问题:

 6.1: tomcat正常启动后访问资源404,项目资源路径配置错误。

  这一版本的IDEA在tomcat配置时,会有自动提示修复,但是如果没有点击修复并且后面自己也没有添加会造成启动后访问资源404.其实自动修复是在deployment下添加了web。

  手动添加web就是在服务器配置页进入之后点击Deployment,然后编辑对应项目,在Project Structure中点击左侧 Artifacts标签,然后在右侧OutPut Layout下点击+ 添加 JavaEE Fact Resources。

如果点击JavaEE Fact Resources 后没有相应的web,可以点击左侧Modules标签 ,然后添加。如下第二张图:

  

 

 

 

ps:在使用IDEA社区版本创建普通maven web项目时,给当前module添加框架的时候会没有JavaEE的选项。如下图。

  解决方案:使用IDEA开发版本。如果是开发版本也没有,可以下载pulgin,并enable。

 

posted on 2021-05-18 12:34  曾经啊  阅读(61)  评论(0编辑  收藏  举报