今天来分享一下如何于本机上在不适用idea等辅助工具的前提下,部署多个tomcat的web项目
我这里以我最近写的SSM项目哈米音乐为例,简单介绍一下项目的大致组成:
首先,项目分为4个模块,如下图所示:
其中,属于web项目的是console(后台)、file(图片服务器)以及portal(后台),所以今天的tomcat本地部署就是部署这三个web
在介绍完之后,我们进入正题,想要在本地部署tomcat,我们就需要目标项目的war包,所以我们需要使用maven先对项目进行打包,然后将打包后的项目放到自己tomcat中webapps文件夹下,如下所示:
之后,我们需要修改tomcat的一些相关配置,我们进入tomcat的conf下,修改server.xml,添加如下代码(需要部署多少个,就加几个,我这里是3个,所以就加了3个)
<!-- 每个service的名称要区别开 -->
<Service name="Catalina1">
<!-- 每个项目的端口号也要进行区分,保证不被占用 -->
<Connector port="8088" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URLEncoding="UTF-8"/>
<!-- 这里的AJP端口同样也要进行区分 -->
<Connector port="8010" protocol="AJP/1.3" redirectPort="8443" secretRequired=""/>
<Engine name="Catalina1" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<!-- 这里是想要部署的对应项目的名称 -->
<Context docBase="ham-file-1.0-SNAPSHOT" path="/" reloadable="true"/>
</Host>
</Engine>
</Service>
<Service name="Catalina2">
<Connector port="8075" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URLEncoding="UTF-8"/>
<Connector port="8011" protocol="AJP/1.3" redirectPort="8443" secretRequired=""/>
<Engine name="Catalina2" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context docBase="ham-portal-1.0-SNAPSHOT" path="/" reloadable="true"/>
</Host>
</Engine>
</Service>
<Service name="Catalina3">
<Connector port="8089" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URLEncoding="UTF-8"/>
<Connector port="8012" protocol="AJP/1.3" redirectPort="8443" secretRequired=""/>
<Engine name="Catalina3" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context docBase="ham-console-1.0-SNAPSHOT" path="/" reloadable="true"/>
</Host>
</Engine>
</Service>
在修改完之后,我们就可以部署了