Intellij idea's mechanism for deploying Web projects through Tomcat

Source: Internet
Author: User

Problem

When you used eclipse to call Tomcat to run a Web project, Eclipse was a straightforward way to update the project directly to the %TOMCAT_HOME%/webapps directory. However, when using IntelliJ idea, no project files can be seen in this directory, and no %TOMCAT_HOME%/conf/Catalina/localhost project configuration files are visible under the directory, so the question is, how is the Web project deployed to Tomcat?

Ideas

Some clues can be found by carefully observing the output log (under MAC OS) when IntelliJ starts Tomcat.

 --oct- .  -: -:10.698INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogServer Version:apache tomcat/8.0. the --oct- .  -: -:10.744INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogServer Built:mar -  .  -: to: theUtc --oct- .  -: -:10.745INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogServer Number:8.0. the. 0 --oct- .  -: -:10.746INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogOS Name:mac OSX --oct- .  -: -:10.747INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogOS Version:10.11. 1 --oct- .  -: -:10.748INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogArchitecture:x86_64 --oct- .  -: -:10.752INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogJava Home:/library/java/javavirtualmachines/jdk1. 8. 0_77. JDK/contents/home/jre --oct- .  -: -:10.756INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogJVM Version:1.8. 0_77-b03 --oct- .  -: -:10.757INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogJVM vendor:oracle Corporation --oct- .  -: -:10.765INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogCatalina_base:/users/didi/library/caches/intellijidea2016. 1/tomcat/unnamed_didi-code --oct- .  -: -:10.766INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogCatalina_home:/opt/apache-tomcat-8.0. the --oct- .  -: -:10.767INFO [main] org. Apache. Catalina. Startup. Versionloggerlistener. LogCommand line argument:-djava. Util. Logging. config. File=/users/didi/library/caches/intellijidea2016. 1/tomcat/unnamed_didi-code/conf/logging. Properties.....

One of the key points in this sentence:

CATALINA_BASE/Users/didi/Library/Caches/IntelliJIdea2016.1/tomcat/Unnamed_didi-code

CATALINA_BASEPoint to a directory (my project is named Didi-code, the application context is code), the following files are in this directory
.
├──conf
│├──catalina
││└──localhost
││└──code.xml
│├──catalina.policy
│├──catalina.properties
│├──context.xml
│├──logging.properties
│├──server.xml
│├──tomcat-users.xml
│├──web.xml
│└──web.xml.0
├──logs
└──work
└──catalina
└──localhost
└──code

This directory is similar to the Tomcat configuration directory, and what does that have to do with our project? We need to start CATALINA_HOME with CATALINA_BASE the difference.

Catalina_home and Catalina_base

Simply put, CATALINA_HOME it's Tomcat's installation directory, and CATALINA_BASE it's Tomcat's working directory. When we want to run multiple Tomcat instances, but do not want to copy multiple tomcat copies, we can configure several different working directories and assign different working directories to each instance when running Tomcat, sharing the running files of the installation directory (under the Bin directory).

So the CATALINA_BASE point is conf, logs, temp, webapps, work, and the shared directory. CATALINA_HOMEThis includes the Tomcat binaries and scripts directory, which is the bin and Lib directories.

After we extract the Tomcat compression package, the two directories are mixed together, so their paths are the same. But when we want to run another Tomcat instance again, we can create a directory that copies conf, logs, temp, webapps, work, and shared to that directory, You can then specify or modify the path in the environment variable when you execute catalina.sh to launch the Tomcat instance CATALINA_BASE .

Analysis

At this point, I roughly analyzed the principle of IntelliJ idea to deploy Web projects through Tomcat.

First IntelliJ will create a separate folder for each Web project, named with the "Unnamed_ Project Name" (which can be modified in. idea/workspace.xml). Each time you start a project, it copies the original directory under the Tomcat directory CATALINA_BASE to that directory, which is the copy of the current Tomcat configuration file to the Unnamed_ Project name folder. CATALINA_BASEthe path is then modified to the directory's path, and then Unnamed_项目名/conf/Catalina/localhost under Add the project's configuration file, such as Code.xml, with the content

<?xml version="1.0" encoding="UTF-8"?><Context path="/code" docBase="/Users/didi/project/CODE-PROJ/didi-code-web/target/code" />

The last boot Tomcat,tomcat except that it will launch the app under WebApps and will load the /conf/Catalina/localhost next configuration, and IntelliJ is the way to "hide" the Web project.

See here you may also find out why the project log file cannot always be found in the Tomcat installation directory because it points to CATALINA_BASE a /Users/didi/Library/Caches/IntelliJIdea2016.1/tomcat/Unnamed_didi-code log file that specifies a relative path that ${catalina.base} exists in that directory.

Intellij idea's mechanism for deploying Web projects through Tomcat

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.