Deploy Java Web Apps to the cloud

In our first tutorial, we built a Java web application and ran it locally. In this tutorial, you will learn how to deploy from Visual Studio Code and run it on Azure in the cloud.

Prerequisites

Important: The JAVA_HOME environment variable must be set to the install location of the JDK to complete this tutorial.

Install the Azure App Service extension

The Azure App Service extension is used to create, manage, and deploy to Azure App Service with key features including:

  • Create new Azure Web App/Deployment Slot
  • Deploy to Azure Web App/Deployment Slot
  • Start, stop, and restart the Azure Web App/Deployment Slot
  • View a Web App's log files
  • Swap Deployment Slots

To install the Azure App Service extension, open the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)) and search for azure app service to filter the results. Select the Microsoft Azure App Service extension. For a more command line Maven-centric experience, you can also check out the Maven plugin for Azure App Service Linux tutorial.

Create a new Web App

Once the extension is installed, you can take the following steps to create a new Web App.

  1. Click Create New Project button on the APP SERVICE Explorer view.
  2. Select a subscription.
  3. Enter a unique name for the new Web App.
  4. Select a location for the new Web App.
  5. Select the OS as Linux.
  6. Select the runtime of the Web App, e.g.Tomcat 8.5 (JRE8).

Create a Web App

Build and deploy to a Web App

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

Create your free Azure account

The deploy process leverages the Azure Account extension (installed along with the Azure Functions extension as an dependency) and you need to sign in with your Azure subscription. If you do not have an Azure subscription, sign up today for a free 30 day account and get $200 in Azure Credits to try out any combination of Azure services.

To log into Azure, run Azure: Sign In from the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)). You can then sign into your account using the Device Login flow. Click on Copy & Open to open your default browser.

Azure sign in code

Paste in the access code and continue the sign in process.

Azure Device Login

Once you have signed in, you can open the command prompt or terminal window and build the project using Maven commands. This will generate a new name.war or name.jar file in the target directory.

mvn clean package

After building the project, open the target directory in VS Code Explorer. Right-click on the name.war or name.jar file and choose Deploy to Web App, and follow the prompts to choose the Web App for your deployment.

Deploy to Web App

Open the Output window in VS Code to view the deployment logs. Once the deployment is completed, it will print out the URL for your Web App. Click the link to open it in a browser, you can see the web app running on Azure!

Greeting from Spring Boot

Note: For more advanced features of App Service, you can check out the Azure App Service extension.

Next steps