An old or failed WAR deployment should be removed through Tomcat Manager when its context path must be released for a replacement. The Manager undeploy command stops the web application, removes the deployed context, and clears the web application artifacts that Manager owns instead of relying on manual file deletion.
The text Manager interface fits repeatable removal because it returns a plain OK or FAIL response. A restricted user with the manager-script role can list deployed contexts, undeploy one path, and leave a transcript that deployment tools or change tickets can keep.
Undeploy is different from stop or reload. Use stop when the application only needs to be taken offline temporarily, use reload when an unpacked application should restart in place, and use undeploy when the deployed WAR, expanded directory, and context entry should be removed from Tomcat for that virtual host.
$ curl --silent --show-error --user deployer:change-this-password http://localhost:8080/manager/text/list OK - Listed applications for virtual host [localhost] /inventory:running:0:inventory /manager:running:0:manager
The account needs the manager-script role. Use a restricted deployment account for text Manager commands, and avoid sharing that account with the manager-gui role.
Context path: /inventory Current state: running
The Manager path parameter must include the leading /. Use / only when the ROOT web application is the target.
Undeploy removes Manager-owned application artifacts under the Host appBase, such as the WAR file, expanded directory, and context XML. Use Manager stop instead when the application should only be unavailable for a short time.
$ curl --silent --show-error --user deployer:change-this-password 'http://localhost:8080/manager/text/undeploy?path=/inventory' OK - Undeployed application at context path [/inventory]
$ curl --silent --show-error --user deployer:change-this-password http://localhost:8080/manager/text/list OK - Listed applications for virtual host [localhost] /manager:running:0:manager
$ curl --silent --show-error --output /dev/null --write-out '%{http_code}\n' http://localhost:8080/inventory/ 404
A 404 is the common direct Tomcat result for a removed context. Behind a proxy, use the status code or health-check response that proves the old application is no longer reachable.
$ ls -ld /opt/tomcat/webapps/inventory /opt/tomcat/webapps/inventory.war ls: cannot access '/opt/tomcat/webapps/inventory': No such file or directory ls: cannot access '/opt/tomcat/webapps/inventory.war': No such file or directory
Replace /opt/tomcat/webapps with the Host appBase for the instance. Package-managed installs often use a path under /var/lib/tomcat*, while archive installs often use $CATALINA_BASE/webapps.