Java – Making a java web application as the root of a domain name in Tomcat 6


I'm currently developing a Java web application myapp and when deployed in Tomcat 6 server, I access myapp with this URL: http://localhost:8080/myapp

Instead I want to access my application using this URL: http://myapp:8080 since myapp will be the only application deployed in my Tomcat 6.

How do I do it?

Best Solution

This can be done in Tomcat in basically two ways:

  1. Set path attribute of <Context> element in Webapp/META-INF/context.xml (or Tomcat/conf/server.xml, depending where you'd like to define it) to an empty String. E.g.

    <Context path="">
  2. Rename it to ROOT.war and Tomcat will automagically deploy it as ROOT.

Outside Tomcat there are more ways to do this, such as (virtual) proxy, URL rewriting with .htaccess, etcetera.