How to deploy war file to tomcat using command prompt?

user3607853 picture user3607853 · Jul 30, 2014 · Viewed 91.1k times · Source

I have created a war file and put into tomcat/webapps. How to deploy a war file to tomcat using command prompt?

Answer

JellicleCat picture JellicleCat · Nov 24, 2014

The earlier answers on this page are correct that you can copy/move the WAR file into place and restart tomcat, but they omit to mention something: you must remove the previously exploded assets (from the previously deployed WAR file) if any are present.

# My tomcat webapps are found at /var/lib/tomcat6/webapps
# The application I wish to deploy is the main (ROOT) application
webapps_dir=/var/lib/tomcat6/webapps
# Remove existing assets (if any)
rm -rf $webapps_dir/ROOT
# Copy WAR file into place
cp example_dir/ROOT.war $webapps_dir
# Restart tomcat
service tomcat6 restart

Modify the following for your own system:

  • Path of your compiled WAR file (to be deployed)
  • Path of your tomcat webapps files
  • How to restart tomcat (i.e. if not installed as a service)