Deploy Java Web Apps to the cloud
In our first tutorial, we built 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):
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 macOS 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.

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
Note: You need to be in the
completedirectory when running commands on the terminal.
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

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

You will also be able to manage it by using the Azure portal.
Your web app will be listed in App Services:

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

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

Next steps
- To see how you can containerize the app and deploy to the cloud, check out Java Container Tutorial
- To learn more about Java Debugging features, see Java Debugging Tutorial

