今天分享一下如何在本地,不依赖于idea部署聚合项目,以我做过的哈米音乐项目为例,项目结构如下:
ham-core模块为公共模块,我们只需将另外三个模块:前台、后台、文件服务器打包,将打好的jar、war包放在Tomcat服务器文件夹下的webapp目录下,如图:
接下来,配置conf下的server.xml文件,在<Server></Server>标签内添加以下内容:
<!-- 每个service的名称要区别开 -->
<Service name="Catalina1"><!-- 每个项目的端口号也要进行区分,保证不被占用 --><Connector port="8087" 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="8084" 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>
端口号要与idea中Tomcat服务器所配置的端口号一致, docBase要根据自己的项目进行修改。
接下来,重启Tomcat,bin->startup.bat,启动之后,我们发现,webapps目录下多了三个文件夹:
conf目录下也多了三个文件夹:
最后,确保idea中Tomcat服务器关闭的情况下,在浏览器内输入相应的端口号进行测试,例如:
这样,Tomcat本地部署项目就成功啦!