Quickstart: Create a Java app in 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.


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

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

Open Azure Cloud Shell

Azure Cloud Shell is an interactive shell environment hosted in Azure and used through your browser. Azure Cloud Shell allows you to use either bash or PowerShell shells to run a variety of tools to work with Azure services. Azure Cloud Shell comes pre-installed with the commands to allow you to run the content of this article without having to install anything on your local environment.

To run any code contained in this article on Azure Cloud Shell, open a Cloud Shell session, use the Copy button on a code block to copy the code, and paste it into the Cloud Shell session with Ctrl+Shift+V on Windows and Linux, or Cmd+Shift+V on macOS. Pasted text is not automatically executed, so press Enter to run code.

You can launch Azure Cloud Shell with:

Option Example/Link
Select Try It in the upper-right corner of a code block. This doesn't automatically copy text to Cloud Shell. Example of Try It for Azure Cloud Shell
Open Azure Cloud Shell in your browser.
Select the Cloud Shell button on the menu in the upper-right corner of the Azure portal. Cloud Shell button in the Azure portal

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.

    <!-- Deploy to Tomcat in App Service Linux           -->
            <!-- Specify v2 schema -->
            <!-- App information -->
            <!-- Java Runtime Stack for App on Linux-->
                <webContainer>tomcat 8.5</webContainer>


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.

Update the following placeholders in the plugin configuration:

Placeholder Description
SUBSCRIPTION_ID The unique ID of the subscription you want to deploy your app to. Default subscription's ID can be found from the Cloud Shell or CLI using the az account show command. For all the available subscriptions, use the az account list command.
RESOURCEGROUP_NAME Name for the new resource group in which to create your app. By putting all the resources for an app in a group, you can manage them together. For example, deleting the resource group would delete all resources associated with the app. Update this value with a unique new resource group name, for example, TestResources. You will use this resource group name to clean up all Azure resources in a later section.
WEBAPP_NAME The app name will be part the host name for the app when deployed to Azure (WEBAPP_NAME.azurewebsites.net). Update this value with a unique name for the new App Service app, which will host your Java app, for example contoso.
REGION An Azure region where the app is hosted, for example westus2. You can get a list of regions from the Cloud Shell or CLI using the az account list-locations command.

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

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 myResourceGroup

This command may take a minute to run.

Next steps