五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

SSM項(xiàng)目頻繁打成war包部署,使用tomcat和maven實(shí)現(xiàn)熱部署配置

發(fā)布日期:2022-02-20 10:38 | 文章來源:源碼中國

背景

眾所周知,我們平時將JavaEE項(xiàng)目開發(fā)完后,需要將項(xiàng)目部署到服務(wù)器的tomcat上。常用的部署方式是將項(xiàng)目打包成war包放到tomcat的webapps下,然后重啟tomcat,然后通過ip地址+端口號訪問。這樣部署本身是沒問題的,但問題在于,如果還是在生產(chǎn)環(huán)境下的話,需要頻繁的更改優(yōu)化項(xiàng)目,那么就需要頻繁的將項(xiàng)目打war包,替換webapps下的war包,操作繁瑣。

接下來我們講述如何實(shí)現(xiàn)本地編程,然后部署項(xiàng)目到遠(yuǎn)程服務(wù)器的tomcat上,實(shí)現(xiàn)熱部署。

所用技術(shù)&工具

  • maven(項(xiàng)目構(gòu)建和依賴管理)
  • tomcat7插件 (部署到tomcat的插件)
  • tomcat服務(wù)器 (web服務(wù)器)
  • 編譯器推薦使用IDEA

1.確保本地具有遠(yuǎn)程tomcat的使用權(quán)限

修改Tomcat下{TOMCAT_HOME}conf/tomcat-users.xml配置文件,添加用戶名、密碼、權(quán)限。

<role rolename="manager-gui" />
<role rolename="manager-script" />
<role rolename="admin-gui" />
<role rolename="admin-script" />
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,admin-gui,admin-script"/>

2.配置Tomcat允許遠(yuǎn)程訪問

在遠(yuǎn)程服務(wù)器的{TOMCAT_HOME}conf/Catalina/localhost/目錄下創(chuàng)建一個manager.xml文件,配置如下內(nèi)容:

<?xml version="1.0" encoding="UTF-8"?>
<Context privileged="true" antiResourceLocking="false" docBase="${catalina.home}/webapps/manager">
     <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>

注:如果只想部分用戶使用,可在allow配置IP,例如

allow="192.168.0.102"

3.重啟遠(yuǎn)程Tomcat

在tomcat的bin目錄下依次執(zhí)行

//關(guān)閉tomcat
./shutdown.sh
//啟動tomcat
./startup.sh

4.測試是否具有使用權(quán)限

訪問tomcat,例如http://192.168.0.102:8080(使用自己的服務(wù)器或是虛擬機(jī)的ip地址)
點(diǎn)擊Manager APP


輸入剛才配置的tomcat的賬號和密碼

如果跳轉(zhuǎn)到這個頁面證明配置完成


當(dāng)然也可以在當(dāng)前頁面實(shí)現(xiàn)war的部署和替換,這也是另一種部署方式,不過依然沒有熱部署方便

問題:如果出現(xiàn)403報(bào)錯如下

403 Access Denied
You are not authorized to view this page.
 
By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager's context.xml file.
 
If you have already configured the Manager application to allow access and you have used your browsers back button, used a saved book-mark or similar then you may have triggered the cross-site request forgery (CSRF) protection that has been enabled for the HTML interface of the Manager application. You will need to reset this protection by returning to the main Manager page. Once you return to this page, you will be able to continue using the Manager application's HTML interface normally. If you continue to see this access denied message, check that you have the necessary permissions to access this application.
 
If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.

解決

修改 /webapps/manager/META_INF/context.xml文件,將文件中對訪問的來源受限設(shè)置注釋

<Context antiResourceLocking="false" privileged="true" >
 <!--注釋這里,去除對訪問權(quán)限的設(shè)置
  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
     allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
     -->
</Context>

然后直接刷新頁面就行了,無需重啟tomcat

5.在maven中配置遠(yuǎn)程Tomcat的管理員賬號

在本地maven的{MAVEN_HOME}/conf/settings.xml文件中節(jié)點(diǎn)下添加如下內(nèi)容:

<!-- 配置可以操作tomcat的用戶名和密碼 -->
<server>
  <id>crocutax</id>
  <!-- server login name -->
  <username>tomcat</username>
  <!-- server login password -->
  <password>tomcat</password>
</server>

6.在項(xiàng)目中配置maven的tomcat7插件

<!-- 配置Tomcat插件 -->
<plugin>
	<groupId>org.apache.tomcat.maven</groupId>
	<artifactId>tomcat7-maven-plugin</artifactId>
	<version>2.2</version>
	<configuration>
		<!-- 此處的名字必須和{MAVEN_HOME}/conf/settings.xml中配置的server節(jié)點(diǎn)的id一致-->
		<server>crocutax</server>
		<!--服務(wù)器端口號-->
		<port>8080</port>
		<!-- 項(xiàng)目發(fā)布的路徑,默認(rèn)就是tomcat/webapps目錄,可以指定深層次目錄,
		留"/",則默認(rèn)在webapps目錄下部署ROOT.war包-->
		<path></path>
		<!-- 注意tomcat7此處的url,不能隨意修改,后綴必須是text,不能是html.
		 如果是本地tomcat部署,用localhost和ip都可以 -->
		<url>http://localhost:8080/manager/text</url>
		<!--<url>http://117.62.110.110:8080/manager/text</url>-->
		<!--解決中文參數(shù)亂碼問題-->
		<uriEncoding>UTF-8</uriEncoding>
		<update>true</update>
		<!--配置在tomcat\conf\tomcat-users.xml中定義的用戶名-->
		<username>tomcat</username>
		<password>tomcat</password>
	</configuration>
</plugin>
  • server : 名字必須和{MAVEN_HOME}/conf/settings.xml中配置的server節(jié)點(diǎn)的id一致
  • port : 服務(wù)器端口號
  • path :項(xiàng)目發(fā)布的路徑,默認(rèn)就是tomcat/webapps目錄,可以指定深層次目錄,留"/",則默認(rèn)在webapps目錄下部署ROOT.war包
  • url : 注意tomcat7此處的url,不能隨意修改,后綴必須是text,不能是html. 如果是本地tomcat部署,用localhost和ip都可以uriEncoding :解決中文參數(shù)亂碼問題
  • update : 熱部署,否則后期會報(bào)錯
  • username :配置{TOMCAT_HOME}\conf\tomcat-users.xml中定義的用戶名
  • password :配置{TOMCAT_HOME}\conf\tomcat-users.xml中定義的密碼

7.在項(xiàng)目中啟動maven的tomcat部署命令

初次部署可以使用 “tomcat7:deploy” 命令(在tomcat的webapps下沒有Root文件夾時使用)

如果已經(jīng)部署過使用 **“tomcat7:redeploy” **命令
若有時遇到項(xiàng)目沖突可以使用命令
-DskipTests的意思跳過測試

clean tomcat7:redeploy -DskipTests

使用的時候出現(xiàn)找不到文件的錯誤,重新編譯或者打包一下即可

使用IDEA如下圖操作即可


當(dāng)然也可以配置快捷啟動



也可使用IDE->Terminal 或 項(xiàng)目根目錄打開dos窗口,輸入maven命令

至此tomcat+maven的熱部署就配置完成了,再也不用為了繁瑣的打包部署而揪心了

總結(jié)

以上所述是小編給大家介紹的SSM項(xiàng)目頻繁打成war包部署,使用tomcat和maven實(shí)現(xiàn)熱部署配置,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對本站網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!

海外服務(wù)器租用

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實(shí)時開通

自選配置、實(shí)時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部