Legend
Legend

Reputation: 116780

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

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?

Upvotes: 48

Views: 117157

Answers (17)

Mashood Ali Khan
Mashood Ali Khan

Reputation: 1

in my case i also encountered the same problem i had tomcat 10.1.34 running and the application was not getting deployed it was throwing 404 error then i uninstalled tomcat and installed tomcat 8.x and the problem was fixed, so basically it was a compatibility error.

Upvotes: 0

Umar Enesi Ibrahim
Umar Enesi Ibrahim

Reputation: 11

TRY UPGRADING YOUR VERSION OF APACHE TOMCAT

I faced similar issues recently. It was after 3 days of painful experience that i realized that the version of apache tomcat (9.x) is not compatible with my web application. I had to upgrade to apache tomcat 10.x.

Upvotes: 1

Mohit Sehgal
Mohit Sehgal

Reputation: 322

I installed tomcat and then placed .war file in webapps folder. Updated the required conf/.xml files as mentioned in the tutorials but when I trying to access my application on the server, I was getting Error- 404.

Root cause for me: Apache Tomcat 10 was installed but my spring boot application was on 2.x. So, I had to upgrade my project to 3.1.5 version and java version 17. Once I updated the version, Error-404 was gone.

Upvotes: 0

Hecatonchier
Hecatonchier

Reputation: 113

For those still encountering this error, it sometimes results because of port conflict with Apache Webserver using the same port 8080, as seen in the error

org.apache.catalina.LifecycleException: Protocol handler initialization failed

Caused by: java.net.BindException: Address already in use

Stopping Apache resolves this. Use

sudo apachectl stop

or the related variant for your operating system, and try relaunching your application via Tomcat

Upvotes: 0

Ram Krishna
Ram Krishna

Reputation: 1

I used to face the same problem. Simply access the application using application name instead of the war file name. (***-0.0.1-SNAPSHOT). It will work.

Upvotes: 0

Archie Maskill
Archie Maskill

Reputation: 13

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

Upvotes: 0

Mukesh Sharma
Mukesh Sharma

Reputation: 1

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..🙏🙏🙏

Upvotes: -1

geppy
geppy

Reputation: 121

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

Upvotes: 6

hello_earth
hello_earth

Reputation: 1562

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.

Upvotes: 13

rogerdpack
rogerdpack

Reputation: 66711

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.

Upvotes: 0

Carrie Zhang
Carrie Zhang

Reputation: 21

I ran into this problem, too.

My simple roundabout solution is to change docBase path.

problem occurs when

docBase=".../tomcat/webapps/app_name.war";

problem solved with

docBase=".../tomcat/webapps/app_foldername/web"

Upvotes: 2

Thomas
Thomas

Reputation: 4999

Assuming that you have full privileges with the Tomcat installation, try going to http://localhost:8080/manager/html/, if you don't know the password to get into that area, look for the tomcat-users.xml file in your ${tomcat-installation}/conf directory, and that should have it. If it has no entries in it then you will want to add an entry like the following to it:

<user username="username" password="password" roles="admin,manager" />

See whether your application shows up in that screen, and if it does, click on the link and see if that gets you anywhere. If it doesn't, then I suggest following ifishers's advice, and looking at the log files to see if it lists any errors.

But long story short, most likely something is screwed up with your project's web.xml

Upvotes: 18

hvgotcodes
hvgotcodes

Reputation: 120138

Did you try

localhost:8080/app

assuming your war file is app.war?

edit for comment -- then your web.xml is screwed up.

Upvotes: -3

Ohlaph
Ohlaph

Reputation: 37

I had the same problem with tomcat and just fixed it by forcing my IDE to create a web.xml file. Mine was missing. It would deploy the project but I would still get the 404 error. I read through several of these tutorials but to no avail. I read somewhere that the web.xml file needed to be configured correctly. Went to find the web.xml in the WEB-INF folder, and there was no folder and no web.xml file. I did a quick google on how to create on using my IDE and then compiled my program with the web.xml output, and it fixed the problem for me. Hope that helps. Cheers!

Upvotes: 1

null
null

Reputation: 3517

I had the same issue, my problem was that I was copying the file via sftp straight into the webapps dir of tomcat which may have caused a polling issue causing it to not deploy correctly. Tomcat monitors the webapps dir and when it sees the .xml it will crack on and do its thing, problem is that maybe everything hasn't been copied across yet. :(

Best to create a staging folder, move or copy the war to that folder and then use linux mv command to move it into the webapps - mv is atomic so tomcat won't do anything until the operation is complete.

Magic.

Credit goes to a very very random post that I found on javarance which in turn lead to : http://pub.admc.com/howtos/tomcat/ch02.html#stagedir-section

Hope this helps someone else :)

Upvotes: 6

Harshil
Harshil

Reputation: 99

I have the same problem. My problem is my application name and war file name are different. I have change war file name to my application name.

Here, when your application is deployed tomcat automatically extract your war file with same name. In my case my service name is my-web-service(i.e.https://localhost:8080/my-web-service/) and my war file name is MY-java-connector-0.0.1-SNAPSHOT.war(this is my project folder name). Now tomcat is looking for my-web=service folder and it finds epicor-java-connector-0.0.1-SNAPSHOT folder. so rename the folder to my-web=service.war and it is working.

Upvotes: 10

Robert Diana
Robert Diana

Reputation: 860

My best guess is that you have not configured the welcome files in your web.xml. If you go to /app/ you need to have some default file available. Typically, people either created an index.html or they have welcome file settings to point the user to the correct jsp.

Upvotes: 4

Related Questions