使用java代码在tomcat中停止webapplication

使用java代码在tomcat中停止webapplication,tomcat,Tomcat,我使用HttpClient。我使用JSF开发了web应用程序。部署到tomcat6.0.29中。 我正在尝试停止应用程序。但它不起作用 ../conf/tomcat-users.xml文件内容 <?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="manager"/> <user username="tomcat" p

我使用HttpClient。我使用JSF开发了web应用程序。部署到tomcat6.0.29中。 我正在尝试停止应用程序。但它不起作用

../conf/tomcat-users.xml文件内容

<?xml version='1.0' encoding='utf-8'?>
      <tomcat-users>
          <role rolename="manager"/>
          <user username="tomcat" password="s3cret" roles="manager" />
     </tomcat-users>
但是我犯了这样的错误

log4j:WARN No appenders could be found for logger (org.apache.commons.httpclient.HttpClient).
log4j:WARN Please initialize the log4j system properly.
Method failed: HTTP/1.1 401 Unauthorized
还有

401 Unauthorized
You are not authorized to view this page. If you have not changed any configuration `files, please examine the file conf/tomcat-users.xml in your installation.

That file will contain the credentials to let you use this webapp.
ou will need to add manager role to the config file listed above. For example:

<role rolename="manager"/>
<user username="tomcat" password="s3cret" roles="manager"/>

For more information - please see the Manager App HOW-TO. 
401未经授权
您无权查看此页面。如果尚未更改任何配置文件,请检查安装中的conf/tomcat-users.xml文件。
该文件将包含允许您使用此webapp的凭据。
您需要向上面列出的配置文件中添加经理角色。例如:
有关更多信息,请参阅Manager应用程序指南。
帮帮我。
提前感谢。

为了停止应用程序,Tomcat需要您在Tomcat-users.xml中创建的用户的凭据,但您的代码不会提供这些凭据

下面是一些可能给你一个线索的clode:

HttpClient client = new HttpClient();
HttpState state = client.getState();

// Set credentials on the client
Credentials credentials = new UsernamePasswordCredentials("tomcat","s3cret");
state.setCredentials( null, null, credentials );

HttpMethod method = new GetMethod(url);

谢谢你的努力。state.setCredentials(null,null,credentials);此方法已弃用。setCredentials(,)是否有其他方法
HttpClient client = new HttpClient();
HttpState state = client.getState();

// Set credentials on the client
Credentials credentials = new UsernamePasswordCredentials("tomcat","s3cret");
state.setCredentials( null, null, credentials );

HttpMethod method = new GetMethod(url);