Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy a war file in Tomcat 7

Tags:

java

tomcat

war

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.


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


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.


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).

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.


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.