1.修改../tomcat/conf/server.xml,原有代碼以下:javascript
<?xml version="1.0" encoding="UTF-8"?> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <Service name="Catalina80"> <Executor name="tomcatThreadPool80" namePrefix="catalina-exec-" maxThreads="1000" maxIdleTime="60000" minSpareThreads="20"/> <Connector port="80" protocol="org.apache.coyote.http11.Http11AprProtocol" executor="tomcatThreadPool80" compression="on" compressionMinSize="2048" noCompressionUserAgents="gozilla, traviata" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,application/json,application/x-javascript" maxThreads="30000" minSpareThreads="512" enableLookups="false" acceptCount="35000" connectionTimeout="40000" disableUploadTimeout="true" URIEncoding="UTF-8" useBodyEncodingForURI="true" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina80" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps80" unpackWARs="true" autoDeploy="true"> </Host> </Engine> </Service> <Service name="Catalina81"> <Executor name="tomcatThreadPool81" namePrefix="catalina-exec-" maxThreads="1000" maxIdleTime="60000" minSpareThreads="20"/> <Connector port="81" protocol="org.apache.coyote.http11.Http11AprProtocol" executor="tomcatThreadPool81" compression="on" compressionMinSize="2048" noCompressionUserAgents="gozilla, traviata" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,application/json,application/x-javascript" maxThreads="30000" minSpareThreads="512" enableLookups="false" acceptCount="35000" connectionTimeout="40000" disableUploadTimeout="true" URIEncoding="UTF-8" useBodyEncodingForURI="true" redirectPort="8443" /> <Connector port="8019" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina81" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps81" unpackWARs="true" autoDeploy="true"> </Host> </Engine> </Service> <Service name="Catalina82"> <Executor name="tomcatThreadPool82" namePrefix="catalina-exec-" maxThreads="1000" maxIdleTime="60000" minSpareThreads="20"/> <Connector port="82" protocol="org.apache.coyote.http11.Http11AprProtocol" executor="tomcatThreadPool82" compression="on" compressionMinSize="2048" noCompressionUserAgents="gozilla, traviata" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,application/json,application/x-javascript" maxThreads="30000" minSpareThreads="512" enableLookups="false" acceptCount="35000" connectionTimeout="40000" disableUploadTimeout="true" URIEncoding="UTF-8" useBodyEncodingForURI="true" redirectPort="8443" /> <Connector port="8029" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina82" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps82" unpackWARs="true" autoDeploy="true"> </Host> </Engine> </Service> <Service name="Catalina83"> <Executor name="tomcatThreadPool83" namePrefix="catalina-exec-" maxThreads="1000" maxIdleTime="60000" minSpareThreads="20"/> <Connector port="83" protocol="org.apache.coyote.http11.Http11AprProtocol" executor="tomcatThreadPool83" compression="on" compressionMinSize="2048" noCompressionUserAgents="gozilla, traviata" compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain,application/json,application/x-javascript" maxThreads="30000" minSpareThreads="512" enableLookups="false" acceptCount="35000" connectionTimeout="40000" disableUploadTimeout="true" URIEncoding="UTF-8" useBodyEncodingForURI="true" redirectPort="8443" /> <Connector port="8039" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina83" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps83" unpackWARs="true" autoDeploy="true"> </Host> </Engine> </Service> </Server>
二、建立目錄 a. 建立須要部署的目錄css
../Tomcat9/webapps80/ROOT,../Tomcat9/webapps81/ROOT,../Tomcat9/webapps82/ROOT,../Tomcat9/webapps83/ROOT,並將須要部署的項目拷貝至該目錄ROOT下;
b. 建立配置文件目錄html
../Tomcat/conf/Catalina80/localhost,../Tomcat/conf/Catalina81/localhost,../Tomcat/conf/Catalina82/localhost,../Tomcat/conf/Catalina83/localhost
3.修改項目代碼 在我嘗試的過程當中發現一個比較容易出錯的地方,就是最好修改web.xml和log4j.properties配置文件。 其中web.xml文件,須要添加webAppRootKey,代碼以下:java
<context-param> <param-name>webAppRootKey</param-name> <param-value>app1.root</param-value> </context-param> <context-param> <param-name>webAppRootKey</param-name> <param-value>app2.root</param-value> </context-param> <context-param> <param-name>webAppRootKey</param-name> <param-value>app3.root</param-value> </context-param>
便可完工。``` 這裏輸入代碼web