Deploy And Undeploy Java EE Web Applications In Tomcat

Deploy or undeploy java web applications in Tomcat are very easy to handle. You can either deploy or undeploy your war file manually or use tomcat manager. This article will show you how to do that.

1. Manually Deploy or Undeploy.

1.1 Manually Deploy.

  1. To manually deploy a .war file is so easy, you just need to copy that .war file to your tomcat webapps folder.
  2. After that, the war file will be extracted to a subfolder under the webapps folder automatically.
  3. Then you can access your web application by browsing the URL like http://localhost:8080/web-app-name/ ( for example http://localhost:8080/Dev2qaWebAppExample/). The web-app-name is usually the same as the .war file name.
  4. If you see a web page with the success message ( for example You are welcome to the demo Java EE web application for dev2qa.com ) that means your web application has been deployed successfully.
  5. If you encounter any errors, you can check the content in the war file extracted folder. The content in it should like below.
    ./
    ├── WebContent
    │   ├── META-INF
    │   │   └── MANIFEST.MF
    │   ├── WEB-INF
    │   │   └── web.xml
    │   ├── index.html
    
  6. The web.xml content should be:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">  
    <!-- This is the java EE web application display name. -->
      <display-name>Dev2qaWebAppExample</display-name>
      <!-- This is the welcome file list. They are the files to be shown when you 
           do not add file name after java EE web application name.
           For example if you browse following url.
           http://localhost:8080/Dev2qaWebAppExample/
           
           Then Tomcat server will find below page first.
           
           http://localhost:8080/Dev2qaWebAppExample/index.html
           
           If not found then find
           http://localhost:8080/Dev2qaWebAppExample/index.htm
           
           If not found then find
           http://localhost:8080/Dev2qaWebAppExample/index.jsp
           ......
           ......
           Until it find one, then show that page content to client.
           
           If no file found, then return a 404 http status code to client.
           -->
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
  7. You can see the comments in the above web.xml to have an in-depth understanding of the welcome file list. If there is not any welcome file that can be found, you will see a 404 not found error web page when you browse the Java EE web application.
  8. The index.html content should be:
    <head>
        <title>This is the demo Java EE web application for dev2qa.com</title>
    </head>
    <body>
        You are welcome to the demo Java EE web application for dev2qa.com
    </body>

1.2 Manually UnDeploy.

  1. It is very easy to UnDeploy a java web application manually. You just need to delete the .war file under the webapps folder.
  2. After a short moment, the extracted folder will also be deleted automatically.

2. Use Tomcat Manager To Deploy Or Undeploy.

2.1. Add A Manager Account.

  1. Browse your local apache tomcat manager URL http://localhost:8080/manager/ in a favorite web browser.
  2. If this is the first time you browse the apache tomcat manager URL, a popup dialog will let you input the user name and password.
  3. Please open the configuration file C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\tomcat-users.xml to add a new user account that can access Tomcat manager GUI.
  4. Add below tomcat user configuration data in the above file. Choose any username and password that you like and roles must be manager-gui.
    <tomcat-users......>
    <user username="admin" password="666666" roles="manager-gui"/>
    </tomcat-users>

2.2 Deploy Java Web Applications.

  1. Now please browse http://localhost:8080/manager/ again and input the username and password you just added.
  2. After login, you will see the Tomcat Web Application Manager page, which lists all the deployed web applications.
  3. Now scroll the page down and go to the Deploy —> WAR file to deploy section.
  4. Click the Browse… button to select the .war file ( for example Dev2qaWebAppExample.war file ) that you want to deploy. After that click the Deploy button.
  5. Then you can find the application in the Applications list section. For example, Browse http://localhost:8080/Dev2qaWebAppExample/ to confirm that it has been deployed successfully.

2.3 Undeploy Java Web Applications.

  1. It is so easy to undeploy applications with Tomcat Manager GUI.
  2. Go to the Applications list section. Click the Undeploy button in the Commands column, then you can find it has been undeployed successfully.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.