Quickstart: Create a Java app on Azure App Service

Azure App Service provides a highly scalable, self-patching web hosting service. This quickstart shows how to use the Azure CLI with the Azure Web App Plugin for Maven to deploy a .jar file, or .war file.

There are also IDE versions of this article. Check out Azure Toolkit for IntelliJ Quickstart or Azure Toolkit for Eclipse Quickstart.

1. Prepare your environment

Before you begin, you must have the following:

The Maven plugin uses account credentials from the Azure CLI to deploy to App Services. Sign in with the Azure CLI before continuing. For more information, see authentication with Maven plugins.

az login


2. Create a Java app

Clone the Spring Boot Getting Started sample project.

git clone https://github.com/spring-guides/gs-spring-boot

Change directory to the completed project.

cd gs-spring-boot/complete


3. Configure the Maven plugin

Run the Maven command below to configure the deployment. This command will help you to set up the App Service operating system, Java version, and Tomcat version.

mvn com.microsoft.azure:azure-webapp-maven-plugin:1.12.0:config
  1. When prompted with Subscription option, select the proper Subscription by entering the number print in the line start.

  2. When prompted with Web App option, accept the default option <create> by pressing enter or select an existing app.

  3. When prompted with OS option, select Windows by entering 3.

  4. When prompted with Pricing Tier option, select B2 by entering 2.

  5. Use the default Java version, Java 8, by pressing enter.

  6. Finally, press enter on the last prompt to confirm your selections.

    Your summary output will look similar to the snippet shown below.

     Please confirm webapp properties
     Subscription Id : ********-****-****-****-************
     AppName : spring-boot-1599007390755
     ResourceGroup : spring-boot-1599007390755-rg
     Region : westeurope
     PricingTier : Basic_B2
     OS : Windows
     Java : 1.8
     WebContainer : java 8
     Deploy to slot : false
     Confirm (Y/N)? : Y
     [INFO] Saving configuration to pom.
     [INFO] ------------------------------------------------------------------------
     [INFO] BUILD SUCCESS
     [INFO] ------------------------------------------------------------------------
     [INFO] Total time: 41.118 s
     [INFO] Finished at: 2020-09-01T17:43:45-07:00
     [INFO] ------------------------------------------------------------------------
     
  1. When prompted with Subscription option, select the proper Subscription by entering the number print in the line start.

  2. When prompted with Web App option, accept the default option <create> by pressing enter or select an existing app.

  3. When prompted with OS option, select Linux by pressing enter.

  4. When prompted with Pricing Tier option, select B2 by entering 2.

  5. Use the default Java version, Java 8, by pressing enter.

  6. Finally, press enter on the last prompt to confirm your selections.

     Please confirm webapp properties
     Subscription Id : ********-****-****-****-************
     AppName : spring-boot-1599007116351
     ResourceGroup : spring-boot-1599007116351-rg
     Region : westeurope
     PricingTier : Basic_B2
     OS : Linux
     RuntimeStack : JAVA 8-jre8
     Deploy to slot : false
     Confirm (Y/N)? : Y
     [INFO] Saving configuration to pom.
     [INFO] ------------------------------------------------------------------------
     [INFO] BUILD SUCCESS
     [INFO] ------------------------------------------------------------------------
     [INFO] Total time: 20.925 s
     [INFO] Finished at: 2020-09-01T17:38:51-07:00
     [INFO] ------------------------------------------------------------------------
     

You can modify the configurations for App Service directly in your pom.xml if needed. Some common ones are listed below:

Property Required Description Version
<schemaVersion> false Specify the version of the configuration schema. Supported values are: v1, v2. 1.5.2
<subscriptionId> false Specify the subscription ID. 0.1.0+
<resourceGroup> true Azure resource group for your Web App. 0.1.0+
<appName> true The name of your Web App. 0.1.0+
<region> true Specifies the region where your Web App will be hosted; the default value is westeurope. All valid regions at Supported Regions section. 0.1.0+
<pricingTier> false The pricing tier for your Web App. The default value is P1V2 for production workload, while B2 is the recommended minimum for Java dev/test. Learn more 0.1.0+
<runtime> true The runtime environment configuration, you could see the detail here. 0.1.0+
<deployment> true The deployment configuration, you could see the details here. 0.1.0+

Be careful about the values of <appName> and <resourceGroup>(helloworld-1590394316693 and helloworld-1590394316693-rg accordingly in the example output), they will be used later.

Report a problem



4. Deploy the app

Deploy your Java app to Azure using the following command.

mvn package azure-webapp:deploy

Once deployment has completed, your application will be ready at http://<appName>.azurewebsites.net/. Open the url with your local web browser. You should see the following display:

Sample app running in Azure App Service

Congratulations! You've deployed your first Java app to App Service.

Report a problem



5. Clean up resources

Delete the Java app and its related resources to avoid incurring any further costs.

az group delete --name <your resource group name; for example: helloworld-1558400876966-rg> --yes

This command may take a minute to run.



Next steps