I have always been curious before, run tomcat in idea, deploy the project to it, run it, and then I go to the tomcat directory to see, I can't find the project I deployed at all, so how does my project run... - -
Later, I checked and checked, tangled and tangled, and then I probably knew what was going on:
For the tomcat configured in idea, idea will not put the project in this path at runtime, but copy a sufficient configuration file to the ${user.home}/.IntelliJIdea/system/tomcat
directory:
That is to say, each project has its own tomcat configuration, which does not interfere with each other.
There is a file in the configuration folder of each project with the /conf/Catalina/localhost/ROOT.xml
following content:
<?xml version="1.0" encoding="UTF-8"?>
<Context path="" docBase="D:\work\项目\target\xxx-web" />
- 1
- 2
Among them, path refers to whether an additional path needs to be added when accessing this project. If it is empty, the project can be accessed directly by using the domain name or ip: 127.0.0.1. This value can be configured in the Run/Debug Configurations in ieda:
docBase refers to the deployment location of the project to be run, which D:\work\项目
is the location of the source code of my project. The target is generated after maven build, and the D:\work\项目\target\xxx-web
directory is the project generated after maven build is completed. The structure is as follows:
And the command for idea to start tomcat is:
That is to say, the entire project running process is: first maven build the project, write the build results to the target directory of the project, then idea copy a tomcat configuration file to ${user.home}/.IntelliJIdea/system/tomcat
it, and then start the catalina.bat file in the tomcat installation directory, Tomcat reads the configuration file, finds the project location, and runs it.
For details, you can see several parameters printed by the idea startup project.
CATALINA_BASE: point to the corresponding project folder under ${user.home}/.IntelliJIdea/system/tomcat , where the conf, work, log and other folders that are unique to each startup project are placed by the idea that is needed for tomcat startup
CATALINA_HOME: point to the folder of tomcat used, use tomcat public bin, jar and other folders
CATALINA_TMPDIR: point to the temp folder under the tomcat folder, generally use the temp folder under CATALINA_BASE, the idea here uses tomcat's own
JRE_HOME: points to the jdk configured by idea
CLASSPATH: bootstrap.jar and tomcat-juli.jar in the bin directory of the tomcat folder