How to deploy a war file in Tomcat 7
Asked Answered
M

13

371

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?

Muttonchops answered 24/2, 2011 at 18:52 Comment(0)
H
351

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.

Hallagan answered 24/2, 2011 at 18:54 Comment(7)
what if the WAR is named "ROOT.war?" Where can I find that WAR?Nutria
What if I want to deploy my sample.war to localhost:8080/somethingdifferent ?Vacuous
you can specify that in META-INF/context.xmlHallagan
The META-INF/context.xml, is it the one in tomcat\conf\context.xml ? Or should it be in my application I am deploying?Vacuous
it can be in both places. I prefer it to be within the applicationHallagan
@Hallagan 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".Sandell
In Ubuntu 14.04.3 the webapps directory is located at /var/lib/tomcat7/webapps .Jannery
P
102

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

Portly answered 3/12, 2014 at 11:34 Comment(1)
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.Jonell
C
61

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.

Cornel answered 24/2, 2011 at 18:55 Comment(3)
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"Sandell
@Mr.H tail the log when you start the server after placing war, you will find why it is not workingCornel
"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. "Percentage
M
55

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).
Milkwhite answered 3/9, 2014 at 9:50 Comment(0)
F
20

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.

Filmy answered 24/2, 2011 at 20:7 Comment(2)
The manager role in Tomcat 7 is now manager-gui. I got bitten by this one.Streamlet
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 failedCountertenor
P
17

There are two ways:

  1. Either you can do hot deployment (Hot deployment means deploying when server is running/up).
  2. Or you can do cold deployment (Cold deployment means deploying when server is stopped).

Just use tomcat manager console for console deployment or simply copy and paste your application in webapp folder of your server's tomcat_home directory.

Note: Make sure if your war file size is more than 52 MB (the default configuration value), you need to make two little changes in web.xml file of Manager application of your webapp folder(Manager application is provided by Apache tomcat by default upon installing the server).

  • Go to the web.xml of the manager application (for instance it could be under /tomcat7/webapps/manager/WEB-INF/web.xml.

  • Increase the max-file-size and max-request-size values in web.xml file:

    <multipart-config>

        <!– 50MB max –>
    
        <max-file-size>52428800</max-file-size>
    
        <max-request-size>52428800</max-request-size>
    
        <file-size-threshold>0</file-size-threshold>
    
     </multipart-config>
    

    Increase the size by putting the values for <max-file-size> and <max-request-size> according to your requirement.

Piggin answered 12/3, 2013 at 11:58 Comment(0)
S
10

This has been working for me:

  1. Create your war file (mysite.war) locally.
  2. Rename it locally to something besides .war, like mysite.www
  3. With tomcat still running, upload mysite.www to webapps directory.
  4. After it finishes uploading, delete the previous version mysite.war
  5. List the directory, watching for the directory /mysite to disappear.
  6. Rename mysite.www to be mysite.war
  7. List the directory, watching for the new /mysite to be created.

If you try uploading the new file as a war file, with tomcat still running, it will attempt to expand it before it is all there. It will fail. Having failed, it will not try again. Thus, uploading a www file, then renaming it, allows the whole war file to be present before tomcat notices it.

Hint, don't forget to check that the war file's owner is tomcat (Use chown)

Sagerman answered 14/3, 2013 at 13:39 Comment(1)
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.Hellespont
R
5

If you installed tomcat7 using apt-get in linux then, deploy your app to /var/lib/tomcat7/webapps/

eg.

sudo service tomcat7 stop

mvn clean package
sudo cp target/DestroyTheWorldWithPeace.war /var/lib/tomcat7/webapps/
#you might also want to make sure war file has permission (`777` not just `+x`)
sudo service tomcat7 start

Also, keep tailing the tomcat log so that you can verify that your app is actually making peace with tomcat.

tail -f /var/lib/tomcat7/logs/catalina.out

The deployed application should appear in http://172.16.35.155:8080/manager/html

Riposte answered 23/9, 2016 at 23:53 Comment(0)
M
5

For deploying the war file over tomcat, Follow the below steps :

  1. Stop the tomcat. powershell->services.msc->OK->Apache Tomcat 8.5->stop(on left hand side).

enter image description here

  1. Put the .war file inside E:\Tomcat_Installation\webapps i.e. webapps folder i.e. put.war (put.war is just an example)

enter image description here

  1. After starting the tomcat(to start tomcat powershell->services.msc->OK->Apache Tomcat 8.5->start )

you will get one folder inside E:\Tomcat_Installation\webapps**put**

enter image description here

In this way you can deploy your war file in Apache Tomcat.

Marymarya answered 8/1, 2019 at 15:2 Comment(0)
B
2

1.Generate a war file from your application
2. open tomcat manager, go down the page
3. Click on browse to deploy the war.
4. choose your war file. There you go!

Blockage answered 30/6, 2017 at 18:9 Comment(0)
V
2

The application name goes into the context of your tomcat deployed URL, eg. http://localhost:Port/applicationName. If your application name is simple then, it should be http://localhost:8080/sample.

By default, Port is 8080, but if you wish to change it, or want to know the port where tomcat is running, simply go to server.xml file in <tomcat-apache-dir>/conf/server.xml, there you can find port & change, eg. <Connector port="8080" redirectPort="8443" connectionTimeout="20000" protocol="HTTP/1.1"/>

If anything goes wrong, check the log files (e.g. <tomcat-apache-dir>/logs/catalina.out)

Venicevenin answered 13/6, 2021 at 10:55 Comment(0)
S
1

Perform the following steps:

  • Stop the Tomcat
  • Right Click on Project and click on "Clean and Build"
  • Go to your project Directory and inside Dist Folder you will get war file that you copy on your tomcat
  • webApp Folder
  • Start the tomcat
  • automatic war file extract and run your project
Stentorian answered 28/5, 2015 at 4:34 Comment(0)
F
0

I followed the instruction in the following link, it works for me. http://www.coderanch.com/t/487178/Tomcat/war-file-show-load

  1. Stop Tomcat

  2. Delete all the logs in tomcat/logs and all files in tomcat/conf/Catalina/localhost

  3. Remove the war file and the directory it created (if it did) from tomact/webapps

  4. Start Tomcat

  5. While watching the logs, copy the war file to the webapps directory again

After this, keep an eye on the catalina.xxxx-xx-xx.log to find out the issue.

Forsythe answered 26/10, 2015 at 2:57 Comment(1)
This is not a valid undeployment / deployment procedure as it interferes with files exclusively managed by Tomcat. The best reference is Tomcat Web Application DeploymentHellespont

© 2022 - 2024 — McMap. All rights reserved.