Deploy Java Web Apps to the cloud

In our first tutorial, we've build a Java web app running locally. This tutorial will show you how to run it in the cloud.

Prepare your Azure account

Before running this sample on Azure, you need to have an Azure subscription and the command line tools.

If you don't have an Azure subscription, you can sign up for a free Azure account:

Create your free Azure account

The Azure Command-Line Interface (CLI):

Install Azure CLI 2.0

Login with Azure CLI

We'll use the Integrated Terminal in VS Code. To open the terminal you can either:

  • Use the ⌃` (Windows, Linux Ctrl+`) keyboard shortcut with the backtick character.
  • Use the View | Integrated Terminal menu command.
  • From the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)), use the View:Toggle Integrated Terminal command.

Note: You can still open an external shell with the Explorer Open in Command Prompt command (Open in Terminal on Mac or Linux) if you prefer to work outside VS Code.

Sign into your Azure account by using the Azure CLI:

az login

Follow the instructions to complete the sign-in process.

Update your project to use Azure CLI for authentication

Open your pom.xml file in your project folder (complete). Find and remove the snippet below in azure-webapp-maven-plugin configuration section so we will authenticate with Azure using Azure CLI, which we've already logged in with.

Remove Authentication

Note: This specific configuration will instead using Service Principal for authentication. More details could be found at Configure Maven to use your Azure Service Principal

Build and deploy your web app to Azure

From the command prompt or terminal window that you were using earlier, rebuild the JAR file using Maven if you made any changes to the pom.xml file; for example:

mvn clean package

Deploy your web app to Azure by using Maven; for example:

mvn azure-webapp:deploy

Maven will deploy your web app to Azure; if the web app does not already exist, it will be created.

When your web has been deployed, you will see a success message from command Line

Deploy Success

by pasting the URL to browser, you will see the sample web app running on Azure!

Greeting cloud

You will also be able to manage it by using the Azure portal.

Your web app will be listed in App Services:

App Service View

And the URL for your web app will be listed in the Overview for your web app:

Overview

You have successfully built a Java web application running in the cloud!

Greeting cloud

Next steps