'uploading the war file to Azure web app, 404 error

In an attempt to learn and publish the war file to azure web app, I am using Azure Cli and publishing the war file. I followed the below article from microsoft documents.

https://docs.microsoft.com/en-us/azure/app-service/deploy-zip?tabs=cli#with-curl

and I used this code: enter image description here

when I checked the files in kudu. I do see the file is updated but the name has changed to app.war rather than what was provided in the cli command.

When I visited the site, it gave me 404. Prior to uploading the war file, when I visited the site it was an empty page and nothing else but now I am getting error.

My app service is using Java 17 on Linux and Tomcat is the server.

enter image description here

Below are the available files after I uploaded the war file

enter image description here

Update: Although I access the kudu but it is not as usual as because I don't see debug console.

enter image description here



Solution 1:[1]

when I checked the files in kudu. I do see the file is updated but the name has changed to app.war rather than what was provided in the cli command.

type=war: Deploy a WAR package. By default, the WAR package is deployed to /home/site/wwwroot/app.war. The target path can be specified with path.

By default the name of the war will be modified.

HTTP Status 404 – Not Found

  • Check your URL
  • Verify whether you have configured yourservlet in Deployment Descriptor (web.xml) file.
  • In web.xml, check whether you have added / before url.
 <url-pattern>/*</url-pattern>

Please refer HTTP Status 404 for more information

Update

enter image description here

Solution 2:[2]

In the off chance someone is attempting to deploy Spring Boot as a WAR file, the following applies to deploying Spring Boot applications as WAR. The CLI commands remain universal, however. Also note, since one would no longer using the embedded Tomcat server, must deploy to Java Tomcat, not Java SE.

Firstly, in my pom file I verified the following:

<packaging>war</packaging>

and

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <scope>provided</scope><!-- THIS LINE MUST BE PRESENT -->
</dependency>

And in my code, I extended SpringBootInitializer:

public class DwBootJarApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(DwBootJarApplication.class);
}
public static void main(String[] args) {
    SpringApplication.run(DwBootJarApplication.class, args);
}

And finally, from command line in project root, to configure pom for Azure:

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

and to deploy:

mvn package azure-webapp:deploy

This is not the only way to deploy, but it is what I find most convenient and is "officially" recommended for development stage of activities.

One final note, it is considered best practice to "pin" Java / Tomcat minor versions to a specific version and not auto update.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 dwellman