title: Running Tomcat from within Eclipse always gives me 404 (but index.html works)
body: <p>first my software stack:</p>
  
  <ul>
  <li>Eclipse 4.2</li>
  <li>Tomcat 7.0.37</li>
  <li>Maven with m2e plugin</li>
  <li>javax.servlet 3.0.1</li>
  <li>Spring WebMVC and Spring Web 3.2.1</li>
  </ul>
  
  <p>I'm using servlet 3 <strong>without web.xml</strong>.</p>
  
  <p><strong>What I did:</strong></p>
  
  <ul>
  <li>Eclipse -> New Maven Project</li>
  <li>edit pom.xml: add Spring and javax.servlet</li>
  <li>Eclipse -> Project properties -> Project facets -> add dynamic web facet</li>
  <li>Eclipse -> Project properties -> Deployment Assembly -> Remove WebContent and add /src/main/webapp</li>
  <li>added <code>javax.servlet.ServletContainerInitializer</code> to /src/main/webapp/META-INF/services and put inside the fully qualified class name which implements <code>WebApplicationInitializer</code></li>
  </ul>
  
  <p>At the moment my project contains about 7 files (3x .java, 1x .jsp, 1x .html, 1x .pom, 1x javax.servlet.ServletContainerInitializer)</p>
  
  <p><strong>What works:</strong></p>
  
  <p>Compiling and war-packaging via Maven and then simply deploy the .war on a standalone Tomcat.</p>
  
  <ul>
  <li><code>http://127.0.0.1/MyApp/</code> shows the index.html</li>
  <li><code>http://127.0.0.1/MyApp/hello</code> shows the hello.jsp</li>
  </ul>
  
  <p><strong>What doesn't work:</strong></p>
  
  <p>If I now try to use Eclipse via <code>Run -&gt; Run on Server</code>. Then I choose my Tomcat directory, etc... The servlet (<code>/hello</code>) just gives an 404. But the index.html works.</p>
  
  <p><strong>The 3 Java Files:</strong></p>
  
  <p>Initializer.java:</p>
  
  <pre><code>public class Initializer implements WebApplicationInitializer {
      @Override
      public void onStartup(ServletContext servletContext) throws ServletException {
          AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
          ctx.register(WebAppConfig.class);
  
          Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
          servlet.setLoadOnStartup(1);
          servlet.addMapping("/");    
      }
  }
  </code></pre>
  
  <p>WebAppConfig.java:</p>
  
  <pre><code>@Configuration
  @ComponentScan("myapp.server")
  @EnableWebMvc
  public class WebAppConfig extends WebMvcConfigurerAdapter {
      @Override
      public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
          configurer.enable();
      }
  
      @Bean
      public InternalResourceViewResolver setupViewResolver() {
          InternalResourceViewResolver resolver = new InternalResourceViewResolver();
          resolver.setPrefix("/WEB-INF/views/");
          resolver.setSuffix(".jsp");
          return resolver;
      }
  }
  </code></pre>
  
  <p>FooController.java:</p>
  
  <pre><code>@Controller
  public class FooController { 
      @RequestMapping("/hello")
      public String helloWorld(Model model) {
          model.addAttribute("wisdom", "Goodbye XML");
          return "hello";
      }
  }
  </code></pre>
  
  <p>If you need any more additional information, just tell me. </p>
  
  <p>Thank you!!</p>
  
  <p>EDIT: Where can I find the log files for Tomcat if it has been started via Eclipse?</p>
  
  <h2>Outputs:</h2>
  
  <p>Eclipse Console (this all comes after starting Tomcat and it <strong>doesn't change</strong> even if I call some URLs like <code>http://localhost:8080/</code> or <code>http://localhost:8080/MyApp/</code>): <a href="http://pastebin.com/gGn0j48T" rel="nofollow noreferrer">http://pastebin.com/gGn0j48T</a></p>
  
  <p>Tomcat logs seem to be saved in <code>.metadata/.plugins/org.eclipse.wst.server.core/tmp0/logs/</code>. There's just one file <code>localhost_access_log.2013-02-20.txt</code> and the output doesn't look interesting: <a href="http://pastebin.com/QmD4wPmA" rel="nofollow noreferrer">http://pastebin.com/QmD4wPmA</a></p>
  
  <p>Now I've done this to get a <code>catalina.out</code>: <a href="https://stackoverflow.com/a/5045247/1321564">https://stackoverflow.com/a/5045247/1321564</a></p>
  
  <p>And here's the output after restarting Tomcat and trying some URLs: The file stays empty... ?!</p>
  
  <p>I've also realized that the following directory is empty on Tomcat: <code>wtpwebapps/MyApp/WEB-INF/lib/</code>. Shouldn't be some Spring libs in there?!</p>