59

I integrated Tomcat 7 in Eclipse. When I start it using Eclipse, it shows that Tomcat is up and running, but when I go to http://localhost:8080 in my browser, it gives me following error:

HTTP Status 404 - /

type Status report

message /

description The requested resource (/) is not available.

Apache Tomcat/7.0.23

I tried changing the port in server.xml just in case if 8080 is used by another service, but it didn't work either. How can I solve it?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Vandan Patel
  • 1,012
  • 1
  • 12
  • 23
  • Maybe eclipse is using a different port for the server when it launches it, regardless of tomcat's configuration. – Ivaylo Slavov Dec 15 '11 at 12:48
  • 2
    What do you expect to see there ? When running in eclipse, there's nothing at / , you'll have to make a webapp which'll show under /yourwebapp/ – nos Dec 15 '11 at 12:57
  • If you are getting a 404, the web server is responding. It even says "Apache Tomcat/7.0.23" it just has no content to respond with. – Stefan Paul Noack Dec 15 '11 at 13:08
  • Just watch this tutorial, but WHOLE! Becayse on 9th minute he starts talking about that. http://javabrains.koushik.org/courses/servlets_intro/lessons/Setting-up – 1392023093user Mar 17 '15 at 22:17

13 Answers13

117

What are you expecting? The default Tomcat homepage? If so, you'll need to configure Eclipse to take control over from Tomcat.

Doubleclick the Tomcat server entry in the Servers tab, you'll get the server configuration. At the left column, under Server Locations, select Use Tomcat installation (note, when it is grayed out, read the section leading text! ;) ). This way Eclipse will take full control over Tomcat, this way you'll also be able to access the default Tomcat homepage with the Tomcat Manager when running from inside Eclipse. I only don't see how that's useful while developing using Eclipse.

enter image description here

The port number is not the problem. You would otherwise have gotten an exception in Tomcat's startup log and the browser would show a browser-specific "Connection timed out" error page (and thus not a Tomcat-specific error page which would impossibly be served when Tomcat was not up and running!)

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 22
    If the section is grayed out, make sure the tomcat does not have any projects configured. If so delete it and the grayed portion will be active and save the configurations and it works fine – Laavaa Feb 24 '13 at 04:55
  • 1
    @Laavaa: that's also very clearly mentioned in the section... "Server must be published with no modules present to make changes" :) – BalusC Feb 24 '13 at 11:16
  • 1
    @BalusC - Yes, if only they used the word projects instead of modules, it would be easier to figure out for a newbie like me. BTW, removing all my projects from tomcat does NOT solve this problem. I'll try restarting eclipse. – Erran Morad Jun 13 '14 at 06:29
  • 6
    @BalusC - Steps to remove the grayed part - `Tomcat server > right click > general {notice the value of location} > switch location {value of location changes} > ok.` Now follow balusC answer. Reason for the 404 errors - The use `workspace metadata option` use the eclipse metadata which does not have a greeting page for admin console. – Erran Morad Jun 13 '14 at 06:44
  • 1
    In additional to the steps mentioned here, I also had to start and stop the server before grayed portion would become active. – kansasian Nov 13 '14 at 05:59
  • 1
    Thanks @BalusC. Sometimes "Use Tomcat Installation" option is disabled. To enable this this Link can help us. http://stackoverflow.com/a/1012459 – Md. Sajedul Karim Oct 17 '15 at 18:57
  • When starting the server it gives the error that /usr/share/tomcat8/backup/catalina.policy does not exist. – zygimantus Feb 14 '17 at 20:14
  • After doing this just restart the server. – Anchal Ajay Jul 09 '21 at 10:24
38

Following steps helped me solve the issue.

  1. In the eclipse right click on server and click on properties.
  2. If Location is set workspace/metadata click on switch location and so that it refers to /servers/tomcatv7server at localhost.server
  3. Save and close
  4. Next double click on server
  5. Under server locations mostly it would be selected as use workspace metadata Instead, select use tomcat installation
  6. Save changes
  7. Restart server and verify localhost:8080 works.
Dirk
  • 3,030
  • 1
  • 34
  • 40
Amey Haldankar
  • 2,223
  • 1
  • 24
  • 22
16

Copy the ROOT (Default) Web App into Eclipse.

Eclipse forgets to copy the default apps (ROOT, examples, etc.) when it creates a Tomcat folder inside the Eclipse workspace.

  • Go to C:\apache-tomcat-7.0.27\webapps, R-click on the ROOT folder and copy it.
  • Then go to your Eclipse workspace, go to the .metadata folder, and search for "wtpwebapps". You should find something like your-eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps (or .../tmp1/wtpwebapps if you already had another server registered in Eclipse).
  • Go to the wtpwebapps folder, right-click, and paste ROOT (say "yes" if asked if you want to merge/replace folders/files).
  • Then reload localhost:8080 to see the Tomcat welcome page.
ronalchn
  • 12,225
  • 10
  • 51
  • 61
Paul Thomas
  • 161
  • 1
  • 2
6

I did what BalusC said but it was not enough for me, I had to clean the Tomcat workdirectory : ( Click right on right on Tomcat in the Servers Tab -> Clean Tomcat Work Directory )

walox
  • 567
  • 1
  • 7
  • 26
5

Please check in your server specification again, if you have changed your port number to something else. And change the port number in your link whatever new port number it is.

Also check whether your server is running properly before you try accessing your localhost.

Advait
  • 107
  • 3
  • 12
5

If you are new in JSP/Tomcat don't modify tomcat's xml files.

I assume you have already deployed web application. But to be sure, try these steps: - right click on your web application - select Run As / Run on Server, choose your Tomcat 7

These steps will deploy and run in the browser your application. Another idea to check if your Tomcat works correctly is to find path where tomcat exists (in eclipse plugin), and copy some working WAR file to webapps (not to wtpwebapps), and then try to run the app.

lukastymo
  • 26,145
  • 14
  • 53
  • 66
3

If options under Server Locations are grayed out, note the message in the section title: "Server must be published with no modules present". To publish the server, right click the name of the server in the Server window and select "Publish".

kansasian
  • 99
  • 2
3

Sometimes cleaning the server works. It worked for me many times.This is only applicable if the program worked earlier but suddenly it stops working.
Steps:
" Right click on Tomcat Server -> Clean. Then restart the server."

Sourav Saha
  • 153
  • 2
  • 12
1

I had the same problem with my localhost project using Eclipse Luna, Maven and Tomcat - the Tomcat homepage would appear fine, however my project would get the 404 error.

After trying many suggested solutions (updating spring .jar file, changing properties of the Tomcat server, add/remove project, change JRE from 1.6 to 7 etc) which did not fix the issue, what worked for me was to just Refresh my project. It seems Eclipse does not automatically refresh the project after a (Maven) build. In Eclipse 3.3.1 there was a 'Refresh Automatically' option under Preferences > General > Workspace however that option doesn't look to be in Luna.

  1. Maven clean-install on the project.
  2. ** Right-click the project and select 'Refresh'. **
  3. Right-click the Eclipse Tomcat server and select 'Clean'.
  4. Right-click > Publish and then start the Tomcat server.
  • 1
    This is probably the nth time, where n > 100, I face this problem, and every time, I discover some action to resolve it. I followed the steps mentioned here, and they worked. – tarekahf Jan 06 '21 at 02:33
1

In my case, I've had to click on my project, then go to File > Properties > *servlet name* and click Restart servlet.

GChuf
  • 1,135
  • 1
  • 17
  • 28
0

For me, my Eclipse installation was hosed - I think because I'd installed struts. After trying a dozen remedies for this error, I re-installed Eclipse, made a new workspace and it was OK. Using Kepler-64-Windows, Tomcat 7, Windows 7.

Kevin S. Miller
  • 913
  • 1
  • 9
  • 21
0

This worked for me:

  1. Project > Build Automatically (Make sure it's turned on)
  2. Project > Clean ...
  3. Right click Tomcat > Properties > General Tab > Switch Location (switch from workspace metadata to Server at localhost.server)
  4. Restart Eclipse
  5. Run Project As Server
Imran Ariffin
  • 185
  • 1
  • 8
0

Apache Tomcat/7.0.23 service is not loaded or enabled. Pls check the service status and other app which is using 8080 port currently. To check this use netstat command and observe whether another app is occupying the port 8080!