(转载)Tomcat 7通过设置不同的端口部署两个项目

原文地址: https://www.jb51.net/article/95141.htm

1、修改../tomcat/conf/server.xml,原有代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<Service name= "Catalina" >
 
  <Connector connectionTimeout= "20000" port= "8080" protocol= "HTTP/1.1" redirectPort= "8443" />
 
  <Connector port= "8009" protocol= "AJP/1.3" redirectPort= "8443" />
 
  <Engine defaultHost= "localhost" name= "Catalina" >
 
  <Realm className= "org.apache.catalina.realm.LockOutRealm" >
  <Realm className= "org.apache.catalina.realm.UserDatabaseRealm" resourceName= "UserDatabase" />
  </Realm>
 
  <Host appBase= "webapps" autoDeploy= "true" name= "localhost" unpackWARs= "true" >
  <Valve className= "org.apache.catalina.valves.AccessLogValve" directory= "logs" pattern= "%h %l %u %t " %r " %s %b" prefix= "localhost_access_log." suffix= ".txt" />
  </Host>
 
  </Engine>
  </Service>

2、添加新端口号,代码如下:

注意修改Service name; Connector port; Engine name; Host appBase

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<Service name= "Catalina1" >
 
  <Connector connectionTimeout= "20000" port= "8090" protocol= "HTTP/1.1" redirectPort= "8443" />
 
  <Connector port= "8009" protocol= "AJP/1.3" redirectPort= "8443" />
 
  <Engine defaultHost= "localhost" name= "Catalina1" >
 
  <Realm className= "org.apache.catalina.realm.LockOutRealm" >
  <Realm className= "org.apache.catalina.realm.UserDatabaseRealm" resourceName= "UserDatabase" />
  </Realm>
 
  <Host appBase= "webapps1" autoDeploy= "true" name= "localhost" unpackWARs= "true" >
  <Valve className= "org.apache.catalina.valves.AccessLogValve" directory= "logs" pattern= "%h %l %u %t " %r " %s %b" prefix= "localhost_access_log." suffix= ".txt" />
  </Host>
 
  </Engine>
  </Service>

3、创建目录

     a. 创建需要部署的目录../Tomcat/webapps1,并将需要部署的项目拷贝至该目录;

     b. 创建配置文件目录../Tomcat/conf/Catalina1/localhost

4、修改项目代码

在我尝试的过程中发现一个比较容易出错的地方,就是最好修改web.xmllog4j.properties配置文件。

其中web.xml文件,需要添加webAppRootKey,代码如下:

?
1
2
3
4
5
//上层节点是web-app
<context-param>
  <param-name>webAppRootKey</param-name>
  <param-value>mos_ms.root</param-value>
  </context-param>

log4j.properties,修改log4j.appender.org.apache.log4j.DailyRollingFileAppender.File的值,代码如下:

?
1
2
3
//具体位置自定义,但是需要在${catalina1.home}中
log4j.appender.A=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A.File=${catalina1.home}/logs/GYL_log/PurePro_

5、做好相应的改动

启动tomcat,webapps目录和webapps1目录的应用都会启动,可以根据不同的端口进行访问里面的项目;假设项目名称是MyApp,对于上述改动那么我们就可以使用以下地址访问:http://localhost:8080/MyApp 或者 http://localhost:8090/MyApp。

猜你喜欢

转载自www.cnblogs.com/bruce-he/p/9230717.html