views:

182

answers:

2

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?

+1  A: 

Im assuming you meen you want your url to be http://localhost:8080 not http://myapp:8080.

If you dont need the default apps that come with tomcat then just go to your webapps directory (where myapp is probably located) and look for another folder called ROOT (in my Tomcat 6). rename ROOT to something else and rename myapp to ROOT. This is a quick and messy way that works because the default host's appBase is webapps and the default app is ROOT.

If you had access to the tomcat/conf/ directory then you could edit the server.xml file but Im not very knowledgeable about server.xml so I wont try and walk you through it.

sgm
+2  A: 

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.

BalusC