資源簡介
python自動化打包java maven工程,并上傳至服務器,簡化服務器war上傳步驟和節約時間
代碼片段和文件信息
#?-*-?coding:utf-8?-*-
import?os
import?paramiko
#?利用Python將java的maven項目自動生成war包或者jar包?并自動上傳至服務器(一般放在tomcat的?webapp?目錄下會自動解壓)
#?做自動化打包需要配置maven環境變量
#?需要上傳服務器的IP地址
serverIp?=?‘xxx.xx.xxx.xx‘
#?服務器的登錄用戶名
serverUser?=?‘root‘
#?服務器的登錄密碼
serverPwd?=?‘123456‘
#?需要生成的war名稱(最終改成項目名上傳的包)
targetFileName?=?‘xxx.war‘
#?一般使用maven打包生成后的名稱(后續需要操作)
createFileName?=?‘xxx-0.0.1-SNAPSHOT.war‘
#?本地項目根目錄
projectPath?=?r‘/D/work/xx(項目)/‘
#?本地項目的target目錄(war?或?jar?包生成的目錄)
localMkDirPath?=?projectPath?+?r‘target/‘
#?遠程服務器的tomcat路徑??xxx是你war解壓的文件夾??一般war上傳至tomcat下?會直接解壓
remoteFileMkDir?=?‘/usr/local/tomcat/webapps/xxx‘
#?遠程服務器下舊war包
remoteFilePath?=?remoteFileMkDir?+?targetFileName
#?刪除本地舊包
def?remove_local_old_file():
????flag?=?os.path.exists(localMkDirPath?+?targetFileName)
????if?flag:
????????os.remove(localMkDirPath?+?targetFileName)
????flag?=?os.path.exists(localMkDirPath?+?createFileName)
????if?flag:
????????os.remove(localMkDirPath?+?createFileName)
????print
#?mvn?命令打包??先進入目錄下??再執行打包命令并改名
def?
評論
共有 條評論