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(); } }