48
votes

I deploy a .war application from Eclipse by adding the "Dynamic Web Module" facet, then right-clicking on the project and selecting "Run As -> Run on Server".

This works great, but by default the project is deployed to the /web context of Tomcat, because the project name is web. Is there a way I can deploy from Eclipse to Tomcat without changing the project name to ROOT?

5

5 Answers

89
votes

You need to go to Server View.. double click on tomcat, this opens a new window (with 2 tabs). Select the one which says Modules, your application would be listed there (with the context path). You can change the context path from /web to anything else from here.

Alternatively, you can open server.xml look for a tag called context. within this tag you'll find the contextroot as /web.. change it.

18
votes

Right click on your project in Eclipse and select Properties->Web Project Settings. Change context name there.

Alternatively you can edit it in .settings/org.eclipse.wst.common.component file inside your project

7
votes

In the Web Project Settings for the project, set the Context root to "/". (Without quotes)

Just in case you are using apache2 with mod_proxy. In my virtual host definition I have a Location entry for the root context:

  <Proxy balancer://ajpCluster>
    BalancerMember ajp://localhost:18009 route=s1
    BalancerMember ajp://localhost:28009 route=s2
  </Proxy>

  # A "Location" entry for hosting static content.  Would put mod_expire settings
  # here
  <Location /resources>
    ProxyPass !  #Don't proxy this location
    ExpiresActive on
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType application/javascript "access plus 1 months"
  </Location>

  #...

  # This must be the last "Location" if you are overloading others, otherwise
  # the others won't load as apache uses the first one listed that matches
  <Location />
    ProxyPass balancer://ajpCluster stickysession=JSESSIONID
  </Location>
4
votes

After you have configured a server in eclipse, you can further configure it and add/remove/tweak any modules (aka contexts/webapps) that you want it to host. You should have a Servers window that list the server (if not: Window > Show View > Servers). Double click on on the server to open the config page. There are 2 tabs, but they are in the bottom left corner. Open Modules, any module you added will be listed. If you want a module to be the default one (so if you type localhost it will server index.jsp, for example) make sure that path says "/". The default value will be what is in your webapps Properties > Web Project Settings, and it usually be the project name. If you set it there, it will not let you leave it blank, so use "/".

Make sure you save the config changes for your Server. You may also need to "publish" it to make the changes propagate out to the actual server.

A last thing to check is find the server install, open conf/server.xml and look for your contexts. You can change the path there as well. Note that path="" equates to "/", tomcat will make that the ROOT app. Also note that Eclipse will create an empty webapp named ROOT when you first publish it (this will also be in server.xml). It is safe to delete it. Even though your deployed app will have the project name as the webapp name, as long as the path is "", it will treat it as the default ROOT.

1
votes

Right click the application > Properties > Web Project setings and set the Context root to ROOT (or to empty - I haven't tried it, so try both and let me know which one worked)