Quickstart: Create a Java app on Azure App Service on Linux

App Service on Linux provides a highly scalable, self-patching, web hosting service using the Linux operating system. This quickstart shows how to use the Azure CLI with the Maven Plugin for Azure App Service to deploy a Java web archive (WAR) file on the Linux operating system.

Note

The same thing can also be done using popular IDEs like IntelliJ and Eclipse. Check out our similar documents at Azure Toolkit for IntelliJ Quickstart or Azure Toolkit for Eclipse Quickstart.

Sample app running in Azure App Service

If you don't have an Azure subscription, create a free account before you begin.

Use Azure Cloud Shell

Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. Cloud Shell lets you use either bash or PowerShell to work with Azure services. You can use the Cloud Shell pre-installed commands to run the code in this article without having to install anything on your local environment.

To launch Azure Cloud Shell:

Option Example/Link
Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell. Example of Try It for Azure Cloud Shell
Go to https://shell.azure.com or select the Launch Cloud Shell button to open Cloud Shell in your browser. Launch Cloud Shell in a new window
Select the Cloud Shell button on the top-right menu bar in the Azure portal. Cloud Shell button in the Azure portal

To run the code in this article in Azure Cloud Shell:

  1. Launch Cloud Shell.

  2. Select the Copy button on a code block to copy the code.

  3. Paste the code into the Cloud Shell session with Ctrl+Shift+V on Windows and Linux, or Cmd+Shift+V on macOS.

  4. Press Enter to run the code.

Create a Java app

Execute the following Maven command in the Cloud Shell prompt to create a new app named helloworld:

mvn archetype:generate -DgroupId=example.demo -DartifactId=helloworld -DarchetypeArtifactId=maven-archetype-webapp

Configure the Maven plugin

To deploy from Maven, use the code editor in the Cloud Shell to open up the project pom.xml file in the helloworld directory.

code pom.xml

Then add the following plugin definition inside the <build> element of the pom.xml file.

<plugins>
    <!--*************************************************-->
    <!-- Deploy to Tomcat in App Service Linux           -->
    <!--*************************************************-->
    <plugin>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-webapp-maven-plugin</artifactId>
        <version>1.7.0</version>       
    </plugin>
</plugins>

The deploy process to Azure App Service uses account credentials from the Azure CLI. Sign in with the Azure CLI before continuing.

az login

Then you can configure the deployment, run the maven command mvn azure-webapp:config in the Command Prompt and use the default configurations by pressing ENTER until you get the Confirm (Y/N) prompt, then press 'y' and the configuration is done.

~@Azure:~/helloworld$ mvn azure-webapp:config
[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< example.demo:helloworld >-----------------------
[INFO] Building helloworld Maven Webapp 1.0-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- azure-webapp-maven-plugin:1.7.0:config (default-cli) @ helloworld ---
[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:
Please confirm webapp properties
AppName : helloworld-1558400876966
ResourceGroup : helloworld-1558400876966-rg
Region : westeurope
PricingTier : Premium_P1V2
OS : Linux
RuntimeStack : TOMCAT 8.5-jre8
Deploy to slot : false
Confirm (Y/N)? : Y

Note

In this article we are only working with Java apps packaged in WAR files. The plugin also supports JAR web applications, visit Deploy a Java SE JAR file to App Service on Linux to try it out.

Navigate to pom.xml again to see the plugin configuration is updated, You can modify other configurations for App Service directly in your pom file 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
<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 westus. All valid regions at Supported Regions section. 0.1.0+
<pricingTier> false The pricing tier for your Web App. The default value is P1V2. 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+

Deploy the app

Deploy your Java app to Azure using the following command:

mvn package azure-webapp:deploy

Once deployment has completed, browse to the deployed application using the following URL in your web browser, for example http://<webapp>.azurewebsites.net.

Sample app running in Azure App Service

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

Clean up resources

In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, delete the resource group by running the following command in the Cloud Shell:

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

This command may take a minute to run.

Next steps