java一鍵自動部署war包,jar包工具java
githubgit
csdn dowload JavaAutoDeployClient-1.1.jargithub
<?xml version="1.0" encoding="utf-8" ?> <config> <threadPoolSize default="5">3</threadPoolSize><!--線程池大小,若是上傳服務器多的話能夠調大,默認5個線程--> <servers> <server> <host>192.168.0.1</host><!--遠程服務器地址--> <userName>root</userName><!--ssh登陸名稱--> <password>123456</password><!--ssh登陸密碼--> <uploads> <upload> <local>C:\test.jar</local><!--本地要上傳至服務器的文件,能夠是相對地址--> <remote>/home</remote><!--服務器目錄--> </upload> </uploads> <commands> <command>/home/restart.sh</command><!--上傳完完文件後要處理的命令,能夠多個--> <command>/home/restart.sh2</command> </commands> <!--服務器應用啓動後的驗證接口,用於驗證最新的代碼是否更新成功,這個接口得本身定義,輪詢驗證直到成功--> <verify requestCount="51" timeDelay="20000" timeGap="2000"><!--requestCount:接口訪問次數,默認50,timeDelay: 服務器命令執行完後多長時間開始啓動驗證接口(單位毫秒,默認10000),timeGap: 輪詢時間間隔(單位毫秒,默認1000) --> <httpapi method="get" url="http://xxx/app/info"/><!--method: http 請求方法;url:http 接口 url--> <httpapi method="post" url="http://xxx/test/testPost"> <param key="aaa">000</param><!--post 參數 鍵值--> <param key="bbb">111</param> </httpapi> </verify> </server> <server> <host>192.168.0.2</host> <userName>root</userName> <password>123456</password> <uploads> <upload> <local>C:\test.jar</local> <remote>/home</remote> </upload> <upload> <local>C:\test2.jar</local> <remote>/home</remote> </upload> </uploads> <commands> <command>/home/restart.sh</command> <command>/home/restart2.sh</command> </commands> <verify requestCount="51" timeDelay="20000" timeGap="2000"> <httpapi method="get" url="http://xxx/app/info"/> </verify> </server> </servers> </config>
java -jar JavaAutoDeployClient-1.1.jar config.xml
<?xml version="1.0" encoding="utf-8" ?> <!--use ssh user password--> <config> <threadPoolSize default="5">3</threadPoolSize> <servers> <server> <host>192.168.0.1</host> <userName>root</userName> <password>123456</password> <uploads> <upload> <local>C:\javawebdeploy.war</local> <remote>/coder/tomcat/apache-tomcat-7.0.55/webapps</remote> </upload> </uploads> <commands> <command>sh /coder/tomcat/apache-tomcat-7.0.55/bin/shutdown.sh</command> <command>rm -rf /coder/tomcat/apache-tomcat-7.0.55/webapps/javawebdeploy</command> <command>sh /coder/tomcat/apache-tomcat-7.0.55/bin/startup.sh</command> </commands> <verify requestCount="51" timeDelay="20000" timeGap="2000"> <httpapi method="get" url="http://xxx/app/info"/> </verify> </server> </servers> </config>
autodeploy.batweb
call maven-package.bat pause java -jar JavaAutoDeployClient-1.1.jar config.xml
maven-package.batapache
mvn clean package -Pprod
public static void main(String args[]){ Map<String,String> uploadMap = new HashMap<String,String>(); uploadMap.put("c:\\test.jar","/home"); List<String> commands = new ArrayList<String>(); commands.add("/home/restart.sh"); List<HttpMethod> apis =new ArrayList<HttpMethod>(); HttpGet httpGet = new HttpGet(); httpGet.setUrl("http://xxxx/app/info"); apis.add(httpGet); HttpPost httpPost = new HttpPost(); httpPost.setUrl("http://xxxx/app/info"); Map<String,String> params = new HashMap<String,String>(); params.put("key","value"); httpPost.setParams(params); apis.add(httpPost); AutoDeploy autoDeploy = AutoDeplyBuilder.create(). setServerInfo("192.168.0.1","root","123456"). setUploadFileInfo(uploadMap). setCommands(commands). setVerifyApi(apis). build(); try { autoDeploy.start(new AutoDeploy.AutoDeployListener() { @Override public void finish() { } @Override public void verifySucess(List<String> log) { } }); } catch (Exception e) { e.printStackTrace(); } }