Skip to content

Azure Web App: Samples

Andy Xu(devdiv) edited this page Aug 24, 2021 · 4 revisions

Table of Content

Web App (on Linux) with Java 8, Tomcat

The following configuration is applicable for below scenario:

  • Reference <serverId> in Maven's settings.xml to authenticate with Azure

  • Web App on Linux

  • Use Java 8 and Tomcat 8.5

  • Deploy a WAR file to context path: /${project.build.finalName} in your Web App server

  • Add Application Settings to your Web App

    <project>
       ...
       <packaging>war</packaging>
       ...
       <build>
          <plugins>
             <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-webapp-maven-plugin</artifactId>
                <version>2.1.0</version>
                <configuration>
                   <!-- Reference <serverId> in Maven's settings.xml to authenticate with Azure -->
                   <auth>
                     <serverId>${AZURE_AUTH}</serverId>
                   </auth>
    
                   <!-- Web App information -->
                   <resourceGroup>${RESOURCEGROUP_NAME}</resourceGroup>
                   <appName>${WEBAPP_NAME}</appName>
                   <region>westeurope</region>
                   <pricingTier>P1V2</pricingTier>
                   <!-- Java Runtime Stack for Web App on Windows-->
                   <runtime>
                     <os>Linux</os>
                       <!-- for now only jre8 is supported for <javaVersion> of linux web app-->
                       <javaVersion>Java 8</javaVersion>
                       <webContainer>Tomcat 8.5</webContainer>
                     </runtime>
                   <appSettings>
                      <property>
                      <!-- Tell Azure which port you want to use, required for springboot
                         jar applications -->
                         <name>PORT</name>
                         <value>8081</value>
                      </property>
                      <!--JVM OPTIONS -->
                      <property>
                         <name>JAVA_OPTS</name>
                         <value>-Xmx512m -Xms512m</value>
                      </property>
                   </appSettings>
                   <!-- Deployment settings -->
                   <deployment>
                     <resources>
                       <resource>
                         <directory>${project.basedir}/target</directory>
                         <includes>
                           <include>*.war</include>
                         </includes>
                       </resource>
                     </resources>
                   </deployment>
                </configuration>
             </plugin>
             ...
          </plugins>
       </build>
    </project>

Web App (on Linux) with Java 8 and JAR deployment

The following configuration is applicable for below scenario:

  • Reference <serverId> in Maven's settings.xml to authenticate with Azure

  • Web App on Linux

  • Use Java 8

  • Deploy an executable jar file to /site/wwwroot/ directory in your Web App server

    <project>
       ...
       <packaging>jar</packaging>
       ...
       <build>
          <finalName>app</finalName>
          <plugins>
             <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-webapp-maven-plugin</artifactId>
                <version>2.1.0</version>
                <configuration>
                   <!-- Reference <serverId> in Maven's settings.xml to authenticate with Azure -->
                   <auth>
                     <serverId>${AZURE_AUTH}</serverId>
                   </auth>
    
                   <!-- Web App information -->
                   <resourceGroup>${RESOURCEGROUP_NAME}</resourceGroup>
                   <appName>${WEBAPP_NAME}</appName>
                   <region>westeurope</region>
                   <pricingTier>P1V2</pricingTier>
    
                   <!-- Java Runtime Stack for Web App on Windows-->
                   <runtime>
                     <os>Linux</os>
                     <javaVersion>Java 8</javaVersion>
                     <webContainer>Java SE</webContainer>
                   </runtime>
                   <!-- Deployment settings -->
                   <deployment>
                     <resources>
                       <resource>
                         <directory>${project.basedir}/target</directory>
                         <includes>
                           <include>*.jar</include>
                         </includes>
                       </resource>
                     </resources>
                   </deployment>
                </configuration>
             </plugin>
             ...
          </plugins>
       </build>
    </project>

Web App (on Windows) with Java 8, Tomcat

The following configuration is applicable for below scenario:

  • Reference <serverId> in Maven's settings.xml to authenticate with Azure

  • Web App on Windows

  • Use Java 8 and Tomcat 8.5

  • Deploy the WAR file to context path: /${project.build.finalName} in your Web App server

  • Add Application Settings to your Web App

    <project>
       ...
       <packaging>war</packaging>
       ...
       <build>
          <plugins>
             <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-webapp-maven-plugin</artifactId>
                <version>2.1.0</version>
                <configuration>
                   <!-- Reference <serverId> in Maven's settings.xml to authenticate with Azure -->
                   <auth>
                     <serverId>${AZURE_AUTH}</serverId>
                   </auth>
    
                   <!-- Web App information -->
                   <resourceGroup>${RESOURCEGROUP_NAME}</resourceGroup>
                   <appName>${WEBAPP_NAME}</appName>
                   <region>westeurope</region>
                   <pricingTier>P1V2</pricingTier>
    
                   <!-- Java Runtime Stack for Web App on Windows-->
                   <runtime>
                     <os>Windows</os>
                     <javaVersion>Java 8</javaVersion>
                     <webContainer>Tomcat 8.5</webContainer>
                   </runtime>
                   <!-- Deployment settings -->
                   <deployment>
                     <resources>
                       <resource>
                         <directory>${project.basedir}/target</directory>
                         <includes>
                           <include>*.war</include>
                         </includes>
                       </resource>
                     </resources>
                   </deployment>
                </configuration>
             </plugin>
             ...
          </plugins>
       </build>
    </project>

Web App for Containers with public DockerHub container image

The following configuration is applicable for below scenario:

  • Reference <serverId> in Maven's settings.xml to authenticate with Azure

  • Web App for Containers

  • Use public DockerHub image springio/gs-spring-boot-docker:latest as runtime stack

  • Add Application Settings to your Web App

    <project>
       ...
       <build>
          <plugins>
             <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-webapp-maven-plugin</artifactId>
                <version>2.1.0</version>
                <configuration>
                   <!-- Reference "azure-auth" from Maven's settings.xml to authenticate with Azure -->
                   <auth>
                     <serverId>azure-auth</serverId>
                 </auth>
    
                   <!-- Web App information -->
                   <resourceGroup>${RESOURCEGROUP_NAME}</resourceGroup>
                   <appName>${WEBAPP_NAME}</appName>
    
                   <region>westeurope</region>
                   <pricingTier>P1V2</pricingTier>
    
                   <!-- Runtime Stack specified by Docker container image -->
                   <runtime>
                     <os>Docker</os>
                     <image>springio/gs-spring-boot-docker:latest</image>
                   </runtime>
                </configuration>
             </plugin>
             ...
          </plugins>
       </build>
    </project>

Web App deployment to an existing App Service Plan

The following configuration is applicable for below scenario:

  • Web App on Linux

  • Use existing App Service Plan

  • Use Java 8 and Tomcat 8.5

  • Use WAR to deploy WAR file to ROOT: / in Tomcat

    <project>
       ...
       <packaging>war</packaging>
       ...
       <build>
          <plugins>
             <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-webapp-maven-plugin</artifactId>
                <version>2.1.0</version>
                <configuration>
    
                   <!-- Web App information -->
                   <resourceGroup>${RESOURCEGROUP_NAME}</resourceGroup>
                   <appName>${WEBAPP_NAME}</appName>
    
                   <!-- Deploy Web App to the existing App Service Plan -->
                   <appServicePlanResourceGroup>${PLAN_RESOURCEGROUP_NAME}</appServicePlanResourceGroup>
                   <appServicePlanName>${PLAN_NAME}</appServicePlanName>
    
                   <!-- Java Runtime Stack for Web App on Linux-->
                   <runtime>
                     <os>Linux</os>
                     <javaVersion>Java 8</javaVersion>
                     <webContainer>Tomcat 8.5</webContainer>
                   </runtime>
                   <deployment>
                     <resources>
                       <resource>
                         <directory>${project.basedir}/target</directory>
                         <includes>
                           <include>*.war</include>
                         </includes>
                       </resource>
                     </resources>
                   </deployment>
                </configuration>
             </plugin>
             ...
          </plugins>
       </build>
    </project>

Deploy to Web App Deployment Slot

The following configuration is applicable for below scenario:

  • Auth use service principle
  • Web App on Linux
  • Use Java 8 and Tomcat 8.5
  • Use WAR deployment to deploy war file to context path /${project.build.finalName} in your Web App server
  • Create a deployment slot and copy configuration from parent Web App then do the deploy
<project>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-webapp-maven-plugin</artifactId>
                <version>2.1.0</version>
                <configuration>
                     <auth>
                        <client>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</client>
                        <tenant>72f988bf-86f1-41af-91ab-2d7cd011db47</tenant>
                        <key>yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy</key>
                        <environment>AZURE</environment>
                    </auth>

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

                    <!-- Deployment Slot Setting -->
                    <deploymentSlot>
                        <name>${SLOT_NAME}</name>
                        <configurationSource>parent</configurationSource>
                    </deploymentSlot>

                    <!-- Java Runtime Stack for Web App on Linux-->
                    <runtime>
                        <os>Linux</os>
                        <javaVersion>Java 8</javaVersion>
                        <webContainer>Tomcat 8.5</webContainer>
                    </runtime>

                    <deployment>
                    <resources>
                      <resource>
                        <directory>${project.basedir}/target</directory>
                        <includes>
                          <include>*.war</include>
                        </includes>
                      </resource>
                    </resources>
                  </deployment>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Clone this wiki locally