40

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

peterh
  • 11,875
  • 18
  • 85
  • 108
user3607853
  • 403
  • 1
  • 5
  • 7

8 Answers8

35

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)
JellicleCat
  • 28,480
  • 24
  • 109
  • 162
33

First add a user role in tomcat-users.xml for role manager-script.

Then to undeploy current app you can use

wget http://username:password@localhost:portnumber/manager/text/undeploy?path=/appname -O - -q

To deploy

wget http://username:password@localhost:portnumber/manager/text/deploy?path=/appname&war=file:/warpath -O - -q
Ankit Gupta
  • 2,529
  • 2
  • 15
  • 26
  • 3
    I kept getting "-O: command not found" but if I wrapped the url part with "" then I had no issues, so for others I recommend doing that. – Quaternion Jul 16 '18 at 17:45
7

You could use wget or curl to deploy an app from command line.

With wget:

wget --http-user=tomcat --http-password=tomcat "http://localhost:8080/manager/text/deploy?war=file:/some/path/SomeWar.war&path=/SomeWar" -O -

But in my case with wget I received this error: "Failed to deploy application at context path ..."

So I solved using curl:

curl -v -u user:password -T app.war 'http://tomcathost/manager/text/deploy?path=/my-app-path&update=true'
Marco C.
  • 1,282
  • 2
  • 15
  • 19
6

To do this, we need to place the WAR file inside the Tomcat CATALINA_HOME/WEBAPPS/ directory. Later, Tomcat will automatically deploy and explode this WAR file.

  • Change active directory of command prompt to your WAR file location
  • Set CATALINA_HOME variable to the path of the Tomcat directory
  • Copy the WAR files

Syntax to copy the WAR file from the current directory in the command line:

copy <your-war-file-name> %CATALINA_HOME%\<your-appBase-name>

Example:

cd C:\MY_WAR_FILE_LOCATION
set CATALINA_HOME="C:\Program Files\Apache\apache-tomcat-7.0.42"
copy MYWARFILE.WAR %CATALINA_HOME%\webapps

Note: If a WAR file is copied into the webapps directory while Tomcat is running, it will not be recognized. Simply restart Tomcat to begin using the web application.

GughaG
  • 171
  • 1
  • 5
0

You can deploy the war file using tomcat manager app, http://tomcat.apache.org/tomcat-7.0-doc/manager-howto.html#Deploy_A_New_Application_Remotely

If you want from command prompt, then as I know

  • Stop tomcat (catalina.bat stop)
  • copy war to webapp
  • restart tomcat (catalina.bat run)
Maas
  • 1,317
  • 9
  • 20
0

As you have already copied the war file to tomcat/webapps, you just need to restart the tomcat to deploy the war file.

Command prompt:

set tomcatPath=D:\apache-tomcat-7.0.50
call "%tomcatPath%"\bin\catalina.bat **stop**
sleep -m 3000 
call "%tomcatPath%"\bin\catalina.bat jpda **start**
Kruti Patel
  • 1,422
  • 2
  • 23
  • 36
Rob
  • 431
  • 2
  • 7
  • 18
0

Using httpie you can upload and deploy the war.

http --auth user:pass PUT http://<tomcatURL>/manager/text/deploy?path=/ < ROOT.war
atomsfat
  • 2,863
  • 6
  • 34
  • 36
0

i tried this it works quite well

curl --request PUT --upload-file webapp.war --basic --user user:password \
  http://hostname:port/manager/text/deploy?path=/web_path\&update=true

it is based on the published tomcat manager API: https://tomcat.apache.org/tomcat-9.0-doc/manager-howto.html#Deploy_A_New_Application_Archive_(WAR)_Remotely