如何使用java在tomcat中启动和停止应用程序?

时间:2012-12-18 01:52:23

标签: tomcat web-applications

我开发了简单的Web应用程序“myapplication”。我部署到Tomcat 6.0.29。

应用程序停止,当我执行“http:// localhost:8080 / manager / stop?path = / myapplication”

可以使用java程序启动应用程序吗? 可以使用java程序停止应用程序吗?

帮帮我。 提前谢谢。


在Windows中不起作用。它适用于linux ubuntu

使用时出错

Process p = r.exec("wget http://tomcatusername:tomcatepassword@localhost:8080/manager/stop?path=/myapplication -O - -q"); 

错误是:

Error occur: java.io.IOException: Cannot run program "wget": 
CreateProcess error=2, The Stystem cannot find the file specified  

任何人都会帮助我。 提前谢谢。

2 个答案:

答案 0 :(得分:0)

试试这个:

Process p = r.exec("wget http://tomcatusername:tomcatepassword@localhost:8080/manager/stop?path=/myapplication -O - -q"); 

答案 1 :(得分:0)

无法使用标准的java网络库。

尝试使用库 org.apache.httpcomponents.httpclient 此代码适用于Tomcat 7

HttpGet httpGet = new HttpGet("http://" + host + ":" + port + "/manager/text/" + action + "?path=/" + app);
        DefaultHttpClient httpClient = new DefaultHttpClient();

        httpClient.getCredentialsProvider().setCredentials(new AuthScope(host, Integer.valueOf(port)),
                new UsernamePasswordCredentials(username, password));
        HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 2000);
        HttpConnectionParams.setSoTimeout(httpClient.getParams(), 2000);
        HttpResponse response = httpClient.execute(httpGet);
相关问题