Deploy And Undeploy Java EE Web Applications In Tomcat

Deploy or undeploy java web applications in tomcat is 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

To manually deploy a war file is so easy, you just need to copy that war file to your tomcat webapps folder as below picture. After that, the war file will be extracted to a sub folder under webapps.

manually deploy java EE web application

Then you can access your web application by browse following url.
http://localhost:8080/Dev2qaWebAppExample/
If you see below page that means your application has been deployed successfully.
browse dev2qa.com sample web application

If you encounter any error, you can check the content in the unzipped folder. The content in it should like below.
the content file in sample web application folder

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>

You can see the comments in above web.xml to have an indepth understanding of welcome file list. If there is not any welcome file that can be found, you will see below web page when you browse the Java EE web application.

READ :   How To Deploy A Maven Project To Tomcat From Eclipse

no welcome file exist in java EE web application folder

The index.html content should be:

<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

It is very easy to UnDeploy it manually. You just need to delete the .war file under webapps. After a short moment the unzipped folder will also be deleted automatically.


2. Use Tomcat Manager to deploy or undeploy

2.1. Add A Manager Account

Input below url into a favorite browser, click enter.
http://localhost:8080/manager/

If this is the first time you browse this url, a popup dialog will let you input the user name and password.
input username and password in popup dialog when browser tomcat manager

Please open below configuration file to add a new user account that can access Tomcat manager gui.

C:\Program Files\Apache Software Foundation\Tomcat 9.0\conf\tomcat-users.xml

Add below user in above file. Choose any username and password that you like and roles must be manager-gui.

<user username="admin" password="666666" roles="manager-gui"/>

add tomcat gui manager account

2.2 Deploy Java Web Applications

Now please browse http://localhost:8080/manager/ again and input the username and password you just added. After login you will see below application list page.
tomcat manager java EE web application list page

Now scroll the page down and go to the deploy section. Click the “Browse…” button to select the .war file that you want to deploy. After that click “Deploy” button.browse and deploy the web application in tomcat manager

Then you can find the application in the Applications list section. Browse http://localhost:8080/Dev2qaWebAppExample/ to confirm that it has been deployed successfully.

2.3 Undeploy Java Web Applications

It is so easy to undeploy applications with Tomcat manager gui. Go to applications list section. Click the “Undeploy” button, then you can find it has been undeployed successfully.
undeploy java EE web application with Tomcat manager gui

READ :   Debug Java EE Web Application In Tomcat Use Eclipse

The attachment is the java web application .war package.

Download “Dev2qaWebAppExample.zip” Dev2qaWebAppExample.zip – Downloaded 139 times – 943 B

Leave a Reply

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.