Deploy Java app and dependencies to Azure App Service in a single step with Maven

Published Jun 23 2021 05:45 PM 2,729 Views
Microsoft

The latest Maven plugin for Azure Web Apps provides a brand new experience that enables you to deploy not only application artifacts such as JAR, WAR, and EAR files but also application dependencies like libraries, module definitions, and startup scripts -- using one single Maven Goal.

 

mvn azure-webapp:deploy

 

Why use it?

Starting from version 1.16.1, the Maven plugin for Azure Web Apps now supports deploying extra file types like JAR, WAR, EAR, libraries, app server module definitions, startup scripts, and more. This new experience gives you:

  • Simplicity: Infrastructure as Code (IaC) by defining everything in your pom.xml and applying changes to Azure with a single Maven deploy Goal. You can easily embed the process in your CI/CD and avoid context switching between multiple tools.
  • One single app restart: Many file changes require Web App restart in order to take effect. The Maven plugin will manage restart policy during the deployment for you so that, no matter how many files are deployed, the Maven plugin will trigger only one restart.
  • Fewer errors: The Maven plugin ensures files are deployed in the right location for Azure App Service. (For example, startup scripts can only take effect if they are deployed under "/home/site/scripts/".) Using this plugin can help you avoid many errors.

How to get started

The Maven plugin for Azure Web Apps greatly simplifies the development experience for Tomcat, Spring Boot, and JBoss EAP apps on Azure App Service. Starting from a Maven project, run the following config goal, follow the wizard to authenticate with Azure, and generate configurations in your pom.xml that are ready to deploy.

 

 mvn com.microsoft.azure:azure-webapp-maven-plugin:1.16.1:config

 

 

      <plugin>
        <groupId>com.microsoft.azure</groupId>
        <artifactId>azure-webapp-maven-plugin</artifactId>
        <version>1.16.1</version>
        <configuration>
          <schemaVersion>v2</schemaVersion>
          <subscriptionId>xxxxxx</subscriptionId>
          <resourceGroup>xxx-rg</resourceGroup>
          <appName>xxx</appName>
          <pricingTier>P1v3</pricingTier>
          <region>westeurope</region>
          <appServicePlanName>asp-xxx</appServicePlanName>
          <appServicePlanResourceGroup>xxx-rg</appServicePlanResourceGroup>
          <runtime>
            <os>Linux</os>
            <javaVersion>Java 8</javaVersion>
            <webContainer>Jbosseap 7.2</webContainer>
          </runtime>
          <deployment>
            <resources>
              <resource>
                <directory>${project.basedir}/target</directory>
                <includes>
                  <include>*.war</include>
                </includes>
              </resource>
            </resources>
          </deployment>
        </configuration>
      </plugin>

 

The above configuration includes only your build artifact. As demonstrated in the PetStore JBoss EAP sample app, you might need to upload a script containing extra steps to prepare the environment before running the artifact. Now, instead of uploading files to the Web App with FTP, deploying the WAR package, and triggering an app restart, you can simply add the configurations below in your pom.xml.

 

<deployment>
  <resources>
    <resource>
      <type>war</type>
      <directory>${project.basedir}/target</directory>
      <includes>
        <include>*.war</include>
      </includes>
    </resource>
    <resource>
      <type>lib</type>
      <directory>${project.basedir}/.scripts/3B-mysql</directory>
      <includes>
        <include>*.jar</include>
      </includes>
    </resource>
    <resource>
      <type>startup</type>
      <directory>${project.basedir}/.scripts/3B-mysql</directory>
      <includes>
        <include>*.sh</include>
      </includes>
    </resource>
    <resource>
      <type>script</type>
      <directory>${project.basedir}/.scripts/3B-mysql</directory>
      <includes>
        <include>*.cli</include>
        <include>*.xml</include>
      </includes>
    </resource>
  </resources>
</deployment>

 

You can then deploy the app with one single command and everything is up and ready!

 

mvn package azure-webapp:deploy

 

Try our tools

Please do not hesitate to try it! Your feedback and suggestions are especially important to us and will help shape our product in future.

 

1 Comment
Deleted
Not applicable

Steps to deploy using maven

@FloydDJohnson3

%3CLINGO-SUB%20id%3D%22lingo-sub-2463819%22%20slang%3D%22en-US%22%3EDeploy%20Java%20app%20and%20dependencies%20to%20Azure%20App%20Service%20in%20a%20single%20step%20with%20Maven%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2463819%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20latest%20Maven%20plugin%20for%20Azure%20Web%20Apps%20provides%20a%20brand%20new%20experience%20that%20enables%20you%20to%20deploy%20not%20only%20application%20artifacts%20such%20as%20JAR%2C%20WAR%2C%20and%20EAR%20files%20but%20also%20application%20dependencies%20like%20libraries%2C%20module%20definitions%2C%20and%20startup%20scripts%20--%20using%20one%20single%20Maven%20Goal.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Emvn%20azure-webapp%3Adeploy%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--436363471%22%20id%3D%22toc-hId--436363498%22%20id%3D%22toc-hId--437437023%22%3EWhy%20use%20it%3F%3C%2FH2%3E%0A%3CP%3EStarting%20from%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fazure-maven-plugins%2Ftree%2Fdevelop%2Fazure-webapp-maven-plugin%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eversion%201.16.1%3C%2FA%3E%2C%20the%26nbsp%3BMaven%20plugin%20for%20Azure%20Web%20Apps%20now%20supports%20deploying%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2Fazure-maven-plugins%2Fwiki%2FAzure-Web-App%3A-Configuration-Details%23resource%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eextra%20file%20types%3C%2FA%3E%26nbsp%3Blike%20JAR%2C%20WAR%2C%20EAR%2C%20libraries%2C%20app%20server%20module%20definitions%2C%20startup%20scripts%2C%20and%20more.%20This%20new%20experience%20gives%20you%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ESimplicity%3A%20Infrastructure%26nbsp%3Bas%26nbsp%3BCode%26nbsp%3B(IaC)%20by%20defining%20everything%20in%20your%20pom.xml%20and%20applying%20changes%20to%20Azure%20with%20a%20single%20Maven%20deploy%20Goal.%20You%20can%20easily%20embed%20the%20process%20in%20your%20CI%2FCD%20and%20avoid%20context%26nbsp%3Bswitching%26nbsp%3Bbetween%20multiple%20tools.%3C%2FLI%3E%0A%3CLI%3EOne%20single%20app%20restart%3A%20Many%20file%20changes%26nbsp%3Brequire%20Web%20App%20restart%20in%20order%20to%20take%20effect.%20The%20Maven%20plugin%20will%20manage%20restart%20policy%20during%20the%20deployment%20for%20you%20so%20that%2C%26nbsp%3Bno%20matter%20how%20many%20files%20are%20deployed%2C%20the%20Maven%20plugin%20will%20trigger%20only%20one%20restart.%3C%2FLI%3E%0A%3CLI%3EFewer%20errors%3A%20The%20Maven%20plugin%20ensures%20files%20are%20deployed%20in%20the%20right%20location%20for%20Azure%20App%20Service.%20(For%20example%2C%20startup%20scripts%20can%20only%20take%20effect%20if%20they%20are%20deployed%20under%20%22%2Fhome%2Fsite%2Fscripts%2F%22.)%20Using%20this%20plugin%20can%20help%20you%20avoid%20many%20errors.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId-2051149362%22%20id%3D%22toc-hId-2051149335%22%20id%3D%22toc-hId-2050075810%22%3EHow%20to%20get%20started%3C%2FH2%3E%0A%3CP%3EThe%20Maven%20plugin%20for%20Azure%20Web%20Apps%20greatly%20simplifies%20the%20development%20experience%20for%20Tomcat%2C%20Spring%20Boot%2C%20and%20JBoss%20EAP%20apps%20on%20Azure%20App%20Service.%26nbsp%3BStarting%20from%20a%20Maven%20project%2C%20run%20the%20following%20config%20goal%2C%20follow%20the%20wizard%20to%20authenticate%20with%20Azure%2C%20and%20generate%20configurations%20in%20your%20pom.xml%20that%20are%20ready%20to%20deploy.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3E%20mvn%20com.microsoft.azure%3Aazure-webapp-maven-plugin%3A1.16.1%3Aconfig%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-basic%22%3E%3CCODE%3E%20%20%20%20%20%20%3CPLUGIN%3E%0A%20%20%20%20%20%20%20%20%3CGROUPID%3Ecom.microsoft.azure%3C%2FGROUPID%3E%0A%20%20%20%20%20%20%20%20%3CARTIFACTID%3Eazure-webapp-maven-plugin%3C%2FARTIFACTID%3E%0A%20%20%20%20%20%20%20%20%3CVERSION%3E1.16.1%3C%2FVERSION%3E%0A%20%20%20%20%20%20%20%20%3CCONFIGURATION%3E%0A%20%20%20%20%20%20%20%20%20%20%3CSCHEMAVERSION%3Ev2%3C%2FSCHEMAVERSION%3E%0A%20%20%20%20%20%20%20%20%20%20%3CSUBSCRIPTIONID%3Exxxxxx%3C%2FSUBSCRIPTIONID%3E%0A%20%20%20%20%20%20%20%20%20%20%3CRESOURCEGROUP%3Exxx-rg%3C%2FRESOURCEGROUP%3E%0A%20%20%20%20%20%20%20%20%20%20%3CAPPNAME%3Exxx%3C%2FAPPNAME%3E%0A%20%20%20%20%20%20%20%20%20%20%3CPRICINGTIER%3EP1v3%3C%2FPRICINGTIER%3E%0A%20%20%20%20%20%20%20%20%20%20%3CREGION%3Ewesteurope%3C%2FREGION%3E%0A%20%20%20%20%20%20%20%20%20%20%3CAPPSERVICEPLANNAME%3Easp-xxx%3C%2FAPPSERVICEPLANNAME%3E%0A%20%20%20%20%20%20%20%20%20%20%3CAPPSERVICEPLANRESOURCEGROUP%3Exxx-rg%3C%2FAPPSERVICEPLANRESOURCEGROUP%3E%0A%20%20%20%20%20%20%20%20%20%20%3CRUNTIME%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3COS%3ELinux%3C%2FOS%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CJAVAVERSION%3EJava%208%3C%2FJAVAVERSION%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CWEBCONTAINER%3EJbosseap%207.2%3C%2FWEBCONTAINER%3E%0A%20%20%20%20%20%20%20%20%20%20%3C%2FRUNTIME%3E%0A%20%20%20%20%20%20%20%20%20%20%3CDEPLOYMENT%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3CRESOURCES%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3CRESOURCE%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3CDIRECTORY%3E%24%7Bproject.basedir%7D%2Ftarget%3C%2FDIRECTORY%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3CINCLUDES%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3CINCLUDE%3E*.war%3C%2FINCLUDE%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C%2FINCLUDES%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3C%2FRESOURCE%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2FRESOURCES%3E%0A%20%20%20%20%20%20%20%20%20%20%3C%2FDEPLOYMENT%3E%0A%20%20%20%20%20%20%20%20%3C%2FCONFIGURATION%3E%0A%20%20%20%20%20%20%3C%2FPLUGIN%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20above%20configuration%20includes%20only%20your%20build%20artifact.%20As%20demonstrated%20in%20the%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure-Samples%2Fmigrate-javaee-app-to-azure-training%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3EPetStore%20JBoss%20EAP%20sample%20app%3C%2FA%3E%2C%20you%20might%20need%20to%20upload%20a%20script%20containing%20extra%20steps%20to%20prepare%20the%20environment%20before%20running%20the%20artifact.%20Now%2C%20instead%20of%20uploading%20files%20to%20the%20Web%20App%20with%20FTP%2C%20deploying%20the%20WAR%20package%2C%20and%20triggering%20an%20app%20restart%2C%20you%20can%20simply%20add%20the%20configurations%20below%20in%20your%20pom.xml.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-basic%22%3E%3CCODE%3E%3CDEPLOYMENT%3E%0A%20%20%3CRESOURCES%3E%0A%20%20%20%20%3CRESOURCE%3E%0A%20%20%20%20%20%20%3CTYPE%3Ewar%3C%2FTYPE%3E%0A%20%20%20%20%20%20%3CDIRECTORY%3E%24%7Bproject.basedir%7D%2Ftarget%3C%2FDIRECTORY%3E%0A%20%20%20%20%20%20%3CINCLUDES%3E%0A%20%20%20%20%20%20%20%20%3CINCLUDE%3E*.war%3C%2FINCLUDE%3E%0A%20%20%20%20%20%20%3C%2FINCLUDES%3E%0A%20%20%20%20%3C%2FRESOURCE%3E%0A%20%20%20%20%3CRESOURCE%3E%0A%20%20%20%20%20%20%3CTYPE%3Elib%3C%2FTYPE%3E%0A%20%20%20%20%20%20%3CDIRECTORY%3E%24%7Bproject.basedir%7D%2F.scripts%2F3B-mysql%3C%2FDIRECTORY%3E%0A%20%20%20%20%20%20%3CINCLUDES%3E%0A%20%20%20%20%20%20%20%20%3CINCLUDE%3E*.jar%3C%2FINCLUDE%3E%0A%20%20%20%20%20%20%3C%2FINCLUDES%3E%0A%20%20%20%20%3C%2FRESOURCE%3E%0A%20%20%20%20%3CRESOURCE%3E%0A%20%20%20%20%20%20%3CTYPE%3Estartup%3C%2FTYPE%3E%0A%20%20%20%20%20%20%3CDIRECTORY%3E%24%7Bproject.basedir%7D%2F.scripts%2F3B-mysql%3C%2FDIRECTORY%3E%0A%20%20%20%20%20%20%3CINCLUDES%3E%0A%20%20%20%20%20%20%20%20%3CINCLUDE%3E*.sh%3C%2FINCLUDE%3E%0A%20%20%20%20%20%20%3C%2FINCLUDES%3E%0A%20%20%20%20%3C%2FRESOURCE%3E%0A%20%20%20%20%3CRESOURCE%3E%0A%20%20%20%20%20%20%3CTYPE%3Escript%3C%2FTYPE%3E%0A%20%20%20%20%20%20%3CDIRECTORY%3E%24%7Bproject.basedir%7D%2F.scripts%2F3B-mysql%3C%2FDIRECTORY%3E%0A%20%20%20%20%20%20%3CINCLUDES%3E%0A%20%20%20%20%20%20%20%20%3CINCLUDE%3E*.cli%3C%2FINCLUDE%3E%0A%20%20%20%20%20%20%20%20%3CINCLUDE%3E*.xml%3C%2FINCLUDE%3E%0A%20%20%20%20%20%20%3C%2FINCLUDES%3E%0A%20%20%20%20%3C%2FRESOURCE%3E%0A%20%20%3C%2FRESOURCES%3E%0A%3C%2FDEPLOYMENT%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22font-family%3A%20inherit%3B%22%3EYou%20can%20then%20deploy%20the%20app%20with%20one%20single%20command%20and%20everything%20is%20up%20and%20ready!%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Emvn%20package%20azure-webapp%3Adeploy%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-247743783%22%20id%3D%22toc-hId-243694899%22%20id%3D%22toc-hId-243694872%22%20id%3D%22toc-hId-242621347%22%3ETry%20our%20tools%3C%2FH2%3E%0A%3CP%3EPlease%20do%20not%20hesitate%20to%20try%20it!%20Your%20feedback%20and%20suggestions%20are%20especially%20important%20to%20us%20and%20will%20help%20shape%20our%20product%20in%20future.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapp-service%2Fquickstart-java%3Ftabs%3Djbosseap%26amp%3Bpivots%3Dplatform-linux%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGet%20started%20with%20JBoss%20EAP%20in%20Azure%20App%20Service%20-%20using%20Maven%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fjboss-eap-app-service-ga-blog%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EGA%20Announcement%20blog%20for%20JBoss%20EAP%20in%20Azure%20App%20Service%3C%2FA%3E%3CA%20href%3D%22https%3A%2F%2Faka.ms%2Fjboss-eap-app-service-ga-blog%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3E%26nbsp%3B%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2463819%22%20slang%3D%22en-US%22%3E%3CP%3EThe%20latest%20Maven%20plugin%20for%20Azure%20Web%20Apps%20provides%20a%20brand%20new%20experience%20that%20enables%20you%20to%20deploy%20not%20only%20application%20artifacts%20such%20as%20JAR%2C%20WAR%2C%20and%20EAR%20files%20but%20also%20application%20dependencies%20like%20libraries%2C%20module%20definitions%2C%20and%20startup%20scripts%20--%20using%20one%20single%20Maven%20Goal.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2463819%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20App%20Service%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EJava%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2487350%22%20slang%3D%22en-US%22%3ERe%3A%20Deploy%20Java%20app%20and%20dependencies%20to%20Azure%20App%20Service%20in%20a%20single%20step%20with%20Maven%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2487350%22%20slang%3D%22en-US%22%3E%3CP%3ESteps%20to%20deploy%20using%20maven%3C%2FP%3E%3CP%3E%40FloydDJohnson3%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Jun 23 2021 07:20 PM
Updated by: