How to deploy a war file in Tomcat 7

923,815

Solution 1

You can access your application from: http://localhost:8080/sample

Deploying or redeploying of war files is automatic by default - after copying/overwriting the file sample.war, check your webapps folder for an extracted folder sample.

If it doesn't open properly, check the log files (e.g. tomcat/logs/catalina.out) for problems with deployment.

Solution 2

step-1. here I'm deploying pos.war First go to tomcat webapps folder and paste it

enter image description here

step-2. go to tomcat->bin folder start tomcat by clicking startup.bat

step-3. go to browser write localhost:port/project name eg. localhost:8080/pos (here my tomcat run on port 8080)

Done....

enter image description here

Solution 3

You just need to put your war file in webapps and then start your server.

it will get deployed.

otherwise you can also use tomcat manager a webfront to upload & deploy your war remotely.

Solution 4

Manual steps - Windows

  1. Copy the .war file (E.g.: prj.war) to %CATALINA_HOME%\webapps ( E.g.: C:\tomcat\webapps )

  2. Run %CATALINA_HOME%\bin\startup.bat

  3. Your .war file will be extracted automatically to a folder that has the same name (without extension) (E.g.: prj)

  4. Go to %CATALINA_HOME%\conf\server.xml and take the port for the HTTP protocol. <Connector port="8080" ... />. The default value is 8080.

  5. Access the following URL:

    [<protocol>://]localhost:<port>/folder/resourceName

    (E.g.: localhost:8080/folder/resourceName)

Don't try to access the URL without the resourceName because it won't work if there is no file like index.html, or if there is no url pattern like "/" or "/*" in web.xml.

The available main paths are here: [<protocol>://]localhost:<port>/manager/html (E.g.: http://localhost:8080/manager/html) and they have true on the "Running" column.


Using the UI manager:

  1. Go to [<protocol>://]localhost:<port>/manager/html/ (usually localhost:8080/manager/html/)

    This is also achievable from [<protocol>://]localhost:<port> > Manager App)

    If you get:

    403 Access Denied

    go to %CATALINA_HOME%\conf\tomcat-users.xml and check that you have enabled a line like this:

    <user username="tomcat" password="tomcat" roles="tomcat,role1,manager-gui"/>
    
  2. In the Deploy section, WAR file to deploy subsection, click on Browse....

    Deploy browse

  3. Select the .war file (E.g.: prj.war) > click on Deploy.

  4. In the Applications section, you can see the name of your project (E.g.: prj).

Solution 5

In addition to the ways already mentioned (dropping the war-file directly into the webapps-directory), if you have the Tomcat Manager -application installed, you can deploy war-files via browser too. To get to the manager, browse to the root of the server (in your case, localhost:8080), select "Tomcat Manager" (at this point, you need to know username and password for a Tomcat-user with "manager"-role, the users are defined in tomcat-users.xml in the conf-directory of the tomcat-installation). From the opening page, scroll downwards until you see the "Deploy"-part of the page, where you can click "browse" to select a WAR file to deploy from your local machine. After you've selected the file, click deploy. After a while the manager should inform you that the application has been deployed (and if everything went well, started).

Here's a longer how-to and other instructions from the Tomcat 7 documentation pages.

Share:
923,815
Admin
Author by

Admin

Updated on August 20, 2021

Comments

  • Admin
    Admin almost 3 years

    I have copied the sample.war file into the webapps directory of Tomcat, and I can access localhost:8080.

    Now how will Tomcat deploy it, I mean do I need to open it in browser? How can I access the application?

  • Mamey
    Mamey almost 13 years
    The manager role in Tomcat 7 is now manager-gui. I got bitten by this one.
  • Kevin Meredith
    Kevin Meredith almost 12 years
    what if the WAR is named "ROOT.war?" Where can I find that WAR?
  • xverges
    xverges over 11 years
    Dropping the .war file in webapps hasn't worked for me, and there was no sign of error in the logs. Doing it from the Tomcat Manager did the trick. Not a clue about why the first method failed
  • Koray Tugay
    Koray Tugay over 11 years
    What if I want to deploy my sample.war to localhost:8080/somethingdifferent ?
  • Bozho
    Bozho over 11 years
    you can specify that in META-INF/context.xml
  • Koray Tugay
    Koray Tugay over 10 years
    The META-INF/context.xml, is it the one in tomcat\conf\context.xml ? Or should it be in my application I am deploying?
  • Bozho
    Bozho over 10 years
    it can be in both places. I prefer it to be within the application
  • Dr.jacky
    Dr.jacky about 9 years
    Unfortunately it doesn't work! Would you like to test my specific war file?! Please download "linshare-core-1.8.4-without-SSO.war" from "forge.linshare.org/projects/linshare/files"
  • Dr.jacky
    Dr.jacky about 9 years
    @Bozho Unfortunately it doesn't work! Would you like to test my specific war file?! Please download "linshare-core-1.8.4-without-SSO.war" from "forge.linshare.org/projects/linshare/files".
  • jmj
    jmj about 9 years
    @Mr.H tail the log when you start the server after placing war, you will find why it is not working
  • haltunbay
    haltunbay over 8 years
    "If the Host autoDeploy attribute is "true", the Host will attempt to deploy and update web applications dynamically, as needed, for example if a new .WAR is dropped into the appBase. For this to work, the Host needs to have background processing enabled which is the default configuration. "
  • user250343
    user250343 over 8 years
    This is not a valid undeployment / deployment procedure as it interferes with files exclusively managed by Tomcat. The best reference is Tomcat Web Application Deployment
  • user250343
    user250343 over 8 years
    While this may work in exceptional cases, it is not a valid undeployment / deployment procedure. mysite.www will create a new context if autodeploy="true" and deleting mysite.war deletes the mysite context under several normal conditions. The best reference is Tomcat Web Application Deployment.
  • derwiwie
    derwiwie almost 8 years
    In Ubuntu 14.04.3 the webapps directory is located at /var/lib/tomcat7/webapps .
  • Anthony De Souza
    Anthony De Souza over 6 years
    Thank you! Additionally, I needed to set permissions to my newly installed Tomcat directory structure so that my WAR could be extracted and log files could be generated.