Switching from a Linux web app to a Windows web app on Azure App Service can cause some differences in the way you deploy and start your Java WAR application. In a Windows web app, you can set up the Java version and container (like Tomcat) using the App Settings.
Here's a general outline of the steps to deploy and start your Java WAR application on a Windows web app:
- Create a Windows web app with your desired App Service Plan using Terraform (which you've likely already done).
- Configure the Java version and container for the web app using App Settings.
- Deploy the WAR file to the web app's
wwwroot/webapps
folder using Azure Pipelines.
For step 2, you can set the Java version and container using the Azure Portal or via Terraform. Here's an example of how to set up the required App Settings using Terraform:
resource "azurerm_app_service" "example" {
# ... other configuration ...
app_settings = {
# Configure the Java version, e.g., Java 11
"WEBSITE_CONFIG_ALLOWED_APP_EXTENSIONS" = ".jar,.war"
"WEBSITE_CONFIG_USE_CUSTOM_JAVA" = "true"
"WEBSITE_CONFIG_JAVA_VERSION" = "11"
"WEBSITE_CONFIG_JAVA_OPTS" = "-Djava.net.preferIPv4Stack=true"
# Configure the container, e.g., Tomcat 9.0
"WEBSITE_CONFIG_JAVA_CONTAINER" = "Tomcat"
"WEBSITE_CONFIG_JAVA_CONTAINER_VERSION" = "9.0"
}
}
For step 3, to deploy the WAR file using Azure Pipelines, update your pipeline definition to include a task for deploying the WAR file to the web app's wwwroot/webapps
folder. Here's an example YAML snippet for an Azure Pipelines task that deploys a WAR file to an Azure Web App:
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'Your-Azure-Subscription-Name'
appType: 'webApp'
WebAppName: 'Your-Web-App-Name'
packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.war'
VirtualApplication: 'wwwroot/webapps'
Replace Your-Azure-Subscription-Name
and Your-Web-App-Name
with the appropriate values for your Azure subscription and web app.
After deploying the WAR file to the wwwroot/webapps
folder, the configured Java container (e.g., Tomcat) should automatically deploy and start the application. You can monitor the application's logs using the Azure Portal or other monitoring tools to ensure that the deployment and startup were successful.