Quickstart: Create a Java web 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 Web Apps (Preview) to deploy a Java web app web archive (WAR) file.

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 a free, interactive shell that you can use to run the steps in this article. Common Azure tools are preinstalled and configured in Cloud Shell for you to use with your account. Just select the Copy button to copy the code, paste it in Cloud Shell, and then press Enter to run it. There are a few ways to open Cloud Shell:

Select Try It in the upper-right corner of a code block. Cloud Shell in this article
Open Cloud Shell in your browser. https://shell.azure.com/bash
Select the Cloud Shell button on the menu in the upper-right corner of the Azure portal. Cloud Shell in the portal

Create a Java app

Execute the following Maven command in the Cloud Shell prompt to create a new web 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.4.0</version>
        <configuration>

            <!-- Web App information -->
            <resourceGroup>${RESOURCEGROUP_NAME}</resourceGroup>
            <appName>${WEBAPP_NAME}</appName>
            <region>${REGION}</region>

            <!-- Java Runtime Stack for Web App on Linux-->
            <linuxRuntime>tomcat 8.5-jre8</linuxRuntime>

        </configuration>
    </plugin>
</plugins>

Note

In this article we are only working with Java apps packaged in WAR files. The plugin also supports JAR web applications. Use the following alternate plugin definition for these applications. This configuration will deploy a JAR built by Maven at ${project.build.directory}/${project.build.finalName}.jar on your local filesystem.

<plugin>
           <groupId>com.microsoft.azure</groupId>
           <artifactId>azure-webapp-maven-plugin</artifactId>
           <version>1.4.0</version>
           <configuration>
               <deploymentType>jar</deploymentType>

          <!-- Web App information -->
           <resourceGroup>${RESOURCEGROUP_NAME}</resourceGroup>
           <appName>${WEBAPP_NAME}</appName>
           <region>${REGION}</region>  

               <!-- Java Runtime Stack for Web App on Linux-->
               <linuxRuntime>jre8</linuxRuntime>
           </configuration>
        </plugin>

Update the following placeholders in the plugin configuration:

Placeholder Description
RESOURCEGROUP_NAME Name for the new resource group in which to create your web 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 web app when deployed to Azure (WEBAPP_NAME.azurewebsites.net). Update this value with a unique name for the new Azure web app, which will host your Java app, for example contoso.
REGION An Azure region where the web 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/helloworld.

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

In this quickstart, you used Maven to create a Java web app, configured the Maven Plugin for Azure Web Apps (Preview), then deployed a web archive packaged Java web app to App Service on Linux. To learn more about using Java with Azure, follow the link below.