Author: Wang Shuli
Source:
After working on a WEB project for a while (based on JSP+JavaBean technology, the server is Apache+Tomcat), we found that our project files are all placed in TOMCAT_HOME\webapps. Although we can configure our projects to other directories through server.xml, when When there are too many projects, server.xml will become extremely bloated and confusing; it will be difficult to manage and maintain.
In order to avoid the above situation from happening, and to make the project easier to manage, what I will introduce to you next is to configure only one or two virtual hosts in server.xml to solve the centralized management of the project, and the configuration files required for each project are also There is no need to add it to server.xml anymore, making server.xml no longer bloated and confusing, but more conducive to management and maintenance.
After talking for a long time, you must be eager to try it, so why not come with me quickly? What are you waiting for! (^_^)
1. Preparation:
Assume that you are already a web programmer and have a certain understanding of tomcat, and you can perform regular configuration on it
. 2. Start the configuration:
1.) First find the server.xml file in the TOMCAT_HOMEconf directory and open it in Notepad;
2.) Find the </Host> tag in the file server.xml;
3.) Create the following information after the </Host> tag:
<Host name="onion" debug="0" appBase="f:StudioOnionWEB_Project" unpackWARs="true" autoDeploy="true">
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="onion_log." suffix=".txt" timestamp="true"/>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="onion_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
</Host>
illustrate:
[onion] is the name or domain name of your host;
[f:StudioOnionWEB_Project] is the starting directory of the virtual host;
[onion_log] is the name of the log file;
[onion_access_log] is the log file name of the access host.
4.) Create a directory for your project in the starting directory of the virtual host and a configuration file with the same name as the project (mine is f:StudioOnionWEB_Project shsc and f:StudioOnionWEB_Project shsc.xml ).
5.) Open the project configuration file you just built to configure the basic information of your project (such as virtual directory and real path, etc.). In short, almost all configurations can be completed in this configuration file. Of course, the deployment of servlets and beans It must be completed in web.xml. This article does not cover this content, so I will not go into details here. The following is the content of my configuration file shsc.xml for reference only:
<Context path="" docBase="F:StudioOnionWEB_Projectshsc" debug="0" reloadable="true" crossContext="true">
</Context>
3. Test open IE and enter http://onion/shsc in the address bar. If you see your jsp page, congratulations on your success; if not, hehehaha... ·Here we go again (^_^).
4. Thank you to the Apache organization for providing me with such a good server, and it is free!
5. Description: If you are satisfied and want to reprint or collect this article, I would like to thank you very much, but please indicate the author: Wang Shuli (^_^)