How to run Java War file (Java Spring Boot) in App service plan as Windows Web App?

Wegscheider, Lukas 10 Reputation points
2023-03-22T12:30:29.3866667+00:00

Hey,

previously I was running a Java WAR application in a linux web app on my App Service Plan but now I have to switch to a windows web app and I am facing some issues. With the linux web app I was able to define a startup command to launch my war file but it seems that windows webapp lack that functionality. Therefore I don't really know, how to manually/automatically start my application.

I deploy my infrastructure with Terraform and deploy my code with azure pipelines.

Thanks!

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,935 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Sedat SALMAN 14,180 Reputation points MVP
    2023-03-22T12:54:27.04+00:00

    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:

    1. Create a Windows web app with your desired App Service Plan using Terraform (which you've likely already done).
    2. Configure the Java version and container for the web app using App Settings.
    3. 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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.