通过程序调用tomcat的manager的text模式的命令来自动部署项目
来源:互联网 发布:淘宝产品摄影价格表 编辑:程序博客网 时间:2024/05/20 20:46
现在我需要做一个tomcat 的自动部署的功能 就是在不重启tomcat的情况下 可以发布 重启、升级应用
1、tomcat的manager的text的模式是可以实现这一功能的
public final static String WEB_LIST="http://localhost:8080/manager/text/list";
public final static String STOP_URL="http://localhost:8080/manager/stop?path=/"; //停止
public final static String START_URL="http://localhost:8080/manager/start?path=/";//启动
public final static String DEPLOY_URL="http://localhost:8080/manager/text/deploy?path=/"; //部署
public final static String UNDEPLOY_URL="http://localhost:8080/manager/text/undeploy?path=/";//卸载
2、由于manager的text命令访问是需要用户名密码才能访问的,所以必须放开访问权限
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<user username="tomcat" password="tomcat" roles="manager-gui,manager-script,manager-jmx"/>
3、程序访问通过HttpURLConnection(我试过Httpclient 但是好像没办法设置用户名密码 )去访问,代码如下
URL url = null; BufferedReader breader = null; InputStream is = null; StringBuffer resultBuffer = new StringBuffer(); try {// String UNDEPLOY_URL="http://localhost:8080/manager/text/undeploy?path=/" appName就是你需要卸载的应用 url = new URL(TomcatCommon.UNDEPLOY_URL+appName); String userPassword = TomcatCommon.UESERNAME + ":" + TomcatCommon.PASSWORD;//此处为用户名密码 String encoding = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());//在classpath中添加rt.jar包,在%java_home%/jre/lib/rt.jar HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestProperty("Authorization", "Basic " + encoding); int statusCode= conn.getResponseCode(); is = conn.getInputStream(); breader = new BufferedReader(new InputStreamReader(is)); String line = ""; while ((line = breader.readLine()) != null) { resultBuffer.append(line); } //http请求失败 if (statusCode != HttpStatus.SC_OK) { LOGGER.info("step-2:卸载"+appName+" ERROR!"); throw new RuntimeException("step-2:卸载"+appName+" ERROR!"); }else{ String responseBody = new String(resultBuffer.toString()); //说明不成功 if(!responseBody.contains("OK")){ LOGGER.info("step-2:卸载"+appName+" ERROR!"); throw new RuntimeException("step-2:卸载"+appName+" ERROR!"); } } LOGGER.info("step-2:卸载"+appName+"成功!"); } catch (MalformedURLException e) { e.printStackTrace(); LOGGER.error("step-2:卸载"+appName+" ERROR !"+e.getMessage()); } finally { if(breader != null) breader.close(); if(is != null) is.close(); }4、其他命令调用方式都可以参照次方式调用
- 通过程序调用tomcat的manager的text模式的命令来自动部署项目
- 通过Tomcat的manager app管理web项目
- 通过Tomcat的manager app管理web项目
- tomcat部署文件夹下手动创建的ftp,在每次项目部署就消失的问题解决
- 通过windows把项目部署到Linux的tomcat中
- Intellij IDEA通过tomcat部署web项目的机制
- 通过配置tomcat的service文件来自定义项目浏览路径
- Linux命令启动关闭tomcat部署的项目
- tomcat部署相关的命令
- 手机浏览器无法访问自己部署的tomcat程序(WEB项目)
- TOMCAT部署项目的方式
- TOMCAT部署项目的方式
- TOMCAT部署项目的方式
- tomcat部署项目的方式
- TOMCAT部署项目的方式
- TOMCAT部署项目的方式
- Tomcat部署项目的方式
- 设置Tomcat的manager
- java装饰设计模式------缓冲流
- hibernate 查询类小结
- PullToRefreshExpandableListView 和BaseExpandableListAdapter
- Linux Pthread——2
- 一个模拟ajax异步上传文件例子
- 通过程序调用tomcat的manager的text模式的命令来自动部署项目
- HttpUrlConnection 的 setDoOutput 与 setDoInput
- JSON.parse()和JSON.stringify()
- [Android基础]Android中如何使用Intent传递对象
- 1的个数
- handler的执行顺序
- 关于限定UITextField的字长
- 测试
- Ubuntu:/etc/rc.local 可执行权限问题