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

This post has been republished via RSS; it originally appeared at: New blog articles in Microsoft Tech Community.

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.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.