Deploy a Spring Boot JAR file app to Azure App Service with Maven and Azure on Linux
In this quickstart, you'll use the Maven Plugin for Azure App Service Web Apps to deploy a Spring Boot application packaged as a Java SE JAR to Azure App Service on Linux. You'll want to choose Java SE deployment over Tomcat and WAR files when you want to consolidate your app's dependencies, runtime, and configuration into a single deployable artifact.
If you don’t have an Azure subscription, create a free account before you begin.
To complete the steps in this tutorial, you'll need to have the following installed and configured:
- The Azure CLI, either locally or through Azure Cloud Shell.
- A supported Java Development Kit (JDK). For more information about the JDKs available for use when developing on Azure, see https://aka.ms/azure-jdks.
- Apache's Maven, Version 3).
- A Git client.
Install and sign in to Azure CLI
The simplest and easiest way to get the Maven Plugin deploying your Spring Boot application is by using Azure CLI.
Sign into your Azure account by using the Azure CLI:
Follow the instructions to complete the sign-in process.
Clone the sample app
In this section, you will clone a completed Spring Boot application and test it locally.
Open a command prompt or terminal window and create a local directory to hold your Spring Boot application, and change to that directory; for example:
md C:\SpringBoot cd C:\SpringBoot
-- or --
md ~/SpringBoot cd ~/SpringBoot
Clone the Spring Boot Getting Started sample project into the directory you created; for example:
git clone https://github.com/spring-guides/gs-spring-boot
Change directory to the completed project; for example:
Build the JAR file using Maven; for example:
mvn clean package
When the web app has been created, start the web app using Maven; for example:
Test the web app by browsing to it locally using a web browser. For example, you could use the following command if you have curl available:
You should see the following message displayed: Greetings from Spring Boot!
Configure Maven Plugin for Azure App Service
In this section, you will configure the Spring Boot project
pom.xml so that Maven can deploy the app to Azure App Service on Linux.
pom.xmlin a code editor.
<build>section of the pom.xml, add the following
<plugin>entry inside the
<plugin> <groupId>com.microsoft.azure</groupId> <artifactId>azure-webapp-maven-plugin</artifactId> <version>1.6.0</version> </plugin>
Then you can configure the deployment, run the maven command
mvn azure-webapp:configin the Command Prompt and use the number to choose these options in the prompt:
- OS: linux
- javaVersion: jre8
- runtimeStack: jre8
When you get the Confirm (Y/N) prompt, press 'y' and the configuration is done.
~@Azure:~/gs-spring-boot/complete$ mvn azure-webapp:config [INFO] Scanning for projects... [INFO] [INFO] -----------------< org.springframework:gs-spring-boot >----------------- [INFO] Building gs-spring-boot 0.1.0 [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] --- azure-webapp-maven-plugin:1.6.0:config (default-cli) @ gs-spring-boot --- [WARNING] The plugin may not work if you change the os of an existing webapp. Define value for OS(Default: Linux): 1. linux [*] 2. windows 3. docker Enter index to use: Define value for javaVersion(Default: jre8): 1. jre8 [*] 2. java11 Enter index to use: Define value for runtimeStack(Default: TOMCAT 8.5): 1. TOMCAT 9.0 2. jre8 3. TOMCAT 8.5 [*] 4. WILDFLY 14 Enter index to use: 2 Please confirm webapp properties AppName : gs-spring-boot-1559091271202 ResourceGroup : gs-spring-boot-1559091271202-rg Region : westeurope PricingTier : Premium_P1V2 OS : Linux RuntimeStack : JAVA 8-jre8 Deploy to slot : false Confirm (Y/N)? : Y
<appSettings>section to the
<azure-webapp-maven-plugin>to listen on the 80 port.
<plugin> <groupId>com.microsoft.azure</groupId> <artifactId>azure-webapp-maven-plugin</artifactId> <version>1.6.0</version> <configuration> <schemaVersion>V2</schemaVersion> <resourceGroup>gs-spring-boot-1559091271202-rg</resourceGroup> <appName>gs-spring-boot-1559091271202</appName> <region>westeurope</region> <pricingTier>P1V2</pricingTier> <!-- Begin of App Settings --> <appSettings> <property> <name>JAVA_OPTS</name> <value>-Dserver.port=80</value> </property> </appSettings> <!-- End of App Settings --> ... </configuration> </plugin>
Deploy the app to Azure
Once you have configured all of the settings in the preceding sections of this article, you are ready to deploy your web app to Azure. To do so, use the following steps:
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:
Maven will deploy your web app to Azure; if the web app or web app plan does not already exist, it will be created for you.
When your web has been deployed, you will be able to manage it through 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:
Verify that the deployment was successful by using the same cURL command as before, using your web app URL from the Portal instead of
localhost. You should see the following message displayed: Greetings from Spring Boot!
Clean up resources
When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.
- From the Azure portal, select Resource group from the left menu.
- Enter gs-spring-boot- in the Filter by name field, the resource group created in this tutorial should have this prefix.
- Select the resource group created in this tutorial.
- Select Delete resource group from the top menu.
To learn more about Spring and Azure, continue to the Spring on Azure documentation center.
For more information about the various technologies discussed in this article, see the following articles: