Deploying a WAR file gives me a 404 Status Code on Tomcat?

Viewed 90415

I am fairly new to Tomcat. I just managed to build a project and exported it as a WAR file. I tried manually copying a WAR file to the Tomcat folder then restarting. It created the folder structure and everything but I get a 404 Status code when I try to reach the application. I tried deploying it through the Tomcat Admin panel but I'm seeing the same behavior. Am I doing anything fundamentally wrong?

12 Answers

In more recent times, this condition might occur if JAVA_HOME points to an earlier version of Java than the code in the WAR. Tomcat might use JAVA_HOME to determine JRE_HOME it shows after running startup.bat in Tomcat's BIN directory. While Tomcat may be happy itself with the Java version it gets, for the application this might not be sufficient. In my case, Tomcat 8.0.49 was running alright with JDK1.7, while the application was not initializing at all (yes, it was a Spring Boot application, WAR was being unpacked, but that's all) - without giving any errors. After setting JAVA_HOME to the location of JDK1.8, the problem was solved.

If your'e using Spring-Boot like me to create your WAR file make sure to add the following to your main Application file.

@SpringBootApplication
public class serverTestApplication extends SpringBootServletInitializer {


    public static void main(String[] args) {
        SpringApplication.run(serverTestApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(serverTestApplication.class);
    }
}

I was stuck on this for awhile, looked through dozens of guides. This is the video that finally showed me I never configured my application properly: https://www.youtube.com/watch?v=05EKZ9Xmfws

FWIW I had this problem and fixed it by discovering I was accessing the wrong host, like "http://wronghost:8080/why_is_this_war_not_there" so if it says "XX.war successfully deployed" in catalina.out/localhost.*.out that may be a hint for followers.

I had the same issue. In my case there were no errors in the log files, I had a welcome page defined, it was listed in the Tomcat manager webapp, and it deployed and worked fine on my dev machine. However, visiting the app at http://example.com/myApp just returned a 404 error.

It turns out the problem was in the Apache config. Apache didn't have a mount point, so it didn't know to proxy those requests to Tomcat.

Adding in the appropriate directive fixed the problem:

ProxyPass /myApp ajp://127.0.0.1:8009/myApp

If you have not created any welcome page like index.html JSP or whatever then create one. project must have an index page. I just created one say index.html and the problem is solved..

Related