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

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?

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

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.

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.

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 :)

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

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.

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"

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!

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..πŸ™πŸ™πŸ™

Did you try
localhost:8080/app
assuming your war file is app.war?
edit for comment -- then your web.xml is screwed up.

Related

My Dynamic Web Project welcome-file doesn't get affected by changes

This is a pretty strage and hassle problem i have here.
I created a Dynamic Web Project in Eclipse and created an HTML file named "inicio.html".
I put this into my web.xml <welcome-file> and all seemed to work okay.
I could Run on server without any problem.
Until i dragged a folder into my webapp.
folder in my project
Now when i run on server my file doesnt change at all, and even when i change the welcome-file from web.xml it doesn't change.
It looks like there's another file somewhere like a copy from the original "inicio.html" that's executing on my server.
this is an example of what's happening
I tried to change my TomCat's web.xml file and it doesn't works.
It's unlikely that the new IMG folder is relevant. Deployment Descriptors aren't really hot swappable.
Make sure automatic building is enabled on the Project menu, and then try right-clicking on the server in the Servers View and choosing "Clean Tomcat Work Directory". Otherwise, you'll need to restart the server for changes to take effect.

Deploying Spring Application on Tomcat 8.5.9 returns 404 1034 error in localhost access log

New poster here so I'll dive right in. Sorry if I miss any important information, let me know and I'll update you.
My problem is that when I go to my application: localhost:8080/GettingStartedSpringMVC/ - I get a 404 error on the screen and a 404 1034 error on the logs but that is it, no other useful information in any log I can find.
I am creating a basic Spring MVC Web application in Java. I am following the "Spring in Action" vol. 4. I have identical code including the test case, which returns success. When I go to "Export > WAR file" and put it into my local Apache instance the WAR file successfully explodes. I am able to access localhost:8080, localhost:8080/test/index.html, and even localhost:8080/GettingStartedSpringMVC/helloworld.html which are .html files I created to make sure deployment was going normally - the last one is inside the project that I cannot access. I have the logs in my apache tomcat instance but there doesn't appear to be anything useful in them - unless I don't know where to look.
If I could find an error, I would be happy to look into it but I can't manage to find anything. Not sure how to post files either - just copy/paste? If anything is needed, I'll add it.
Did you check Catalina.out and other server logs inside logs folder?
Also, double check if your static files are not in web-inf which is not accessible.
In addition, check that javac is on the path of you are using JSP
Turns out there was an error in one of the files that meant it did not scan for all the components. Also, was not able to confirm but there potentially may have been an issue with the WAR bringing necessary JAR files. I placed them in the lib file instead of relying on the Eclipse linking.
Thanks,

Why Tomcat works fine when I put a .jsp but with a .html doesn't works?

I'm working with eclipse and I created a project, I put a test.html and test.jsp file in the root folder. In the URL of the Google Chrome I put this:
http://localhost:8080/project/test.html Error 404
http://localhost:8080/project/test.jsp Works (hello world!)
What is happening?
Double check if your test.html exists under this path:
"Workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\project"
If exists, then it should be accessed normally, if not then you have to clean/build your application correctly or even try to restart eclipse.
Based on your follow-up comments about the custom Tomcat install and the project error message, it sounds like you either don't have Eclipse properly configured to use your Tomcat server, or you don't have your project associated with the Tomcat server you've set up, and so perhaps your changes arent being deployed properly. See if that issue has a quick fix suggestion (right click it) or go through your project settings and verify your selected server runtime. Sorry on phone can't give specific instructions.

Tomcat Error 404 in Eclipse but it worked before

I understand that many people have mine problem, but the causes may be different, in fact I have not solved looking at other solutions. To be noted that initially my application tests worked!! [run as -> server (after I configure the server)]. Days ago, I move the Tomcat's folder in another root, and then, after that, there was an error for the root. I resolved this step copying tomcat's folder in the old root. But now, whe I run my application as a server, there are "HTTP Status 404 - " with no message and the descripton: "The requested resource is not available.". Moreover, in the console there are this text copyed in pastebin.com:
http://pastebin.com/kv5H2MrJ
Somebody can help me? Please
Thanks
First, you just cannot access files and (sub)folders in the WEB-INF folder directly, the servlet engine (Tomcat in your case) just won't allow you to do that. That is by specification.
Second, *.java files are not to be accessed directly, they are to be compiled and deployed.
Third, and most important: get back to the basics, and read the tutorial. Or at least this shorter one.

SEVERE: PWC6117: File not found - Jetty

We are facing this issue in production environment but unable to track it out.
Technology: JSP/Servlets,
Jetty Server Version: jetty-distribution-8.1.15,
Following is exception, what we are getting in Jetty Logs:
2014_08_10.stderrout.log.05300:
SEVERE: PWC6117: File "%2Ftmp%2Fjetty-0.0.0.0-8090-ExpireApp.war-_ExpireApp-any-%2Fwebapp%2FExpiry.jsp" not found
The application worked fine before but end users are unable to access .jsp file and we need a restart for the same but we want to get it resolved. Please help
We see things like this when there is a process in the background that cleans up tmp directories and things like that. The jsp gets compiled there and then gets scraped away and the JSP impl still believes it to be there resulting in an error like this.
Oh Sorry, i have not shared answer before.
Here it is:
Issue: By Default Jetty unpacks .WAR file in /TMP directory of Linux. The /TMP directory got cleared after some days by some scripts which i am unable to find.
Resolution: I have created another directory named β€˜work’ in jetty, where Jetty will unpack .WAR by default, thereby preventing jetty to unpack contents in /TMP.
So issue was unpacked contents got deleted and after restart it got created again. This time i checked unpacked content before restarting so i got what issue actually was :)
Thanks all for help
I have meet the same SEVERE: PWC6117: error, the reason is
I changed below code(Spring mvc controller)
model.addAttribute("foo", foo);
return "foo";
to just
return model;

Categories