Deploy Java Web Apps to the cloud
Prepare your Azure account
Before running this sample application on Azure, you need to have an Azure subscription and the Azure command line tools.
If you don't have an Azure subscription, you can sign up for a free Azure account:
Login with Azure CLI
To run the 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 also 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:
Follow the instructions to complete the sign-in process.
Update your project to use Azure CLI for authentication
pom.xml file in your project folder (
complete). Find and remove the snippet below in the azure-webapp-maven-plugin
configuration section so that you will authenticate with Azure using the Azure CLI, which you did in the previous step.
Note: This specific configuration will now use Azure 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 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 in the terminal.
Deploy your web app to Azure by using Maven:
Maven will deploy your web app to Azure. If the web app does not already exist, it will be created.
When your web app has been deployed, you will see a success message on the command line:
By pasting the URL into a web browser, you can see the sample web app running on Azure!
You will also be able to manage it using the Azure portal.
Your web app will be listed under App Services:
The URL for your web app will be listed in the Overview for your web app:
You have successfully deployed a Java web application to the cloud!