30
votes

I'm using Tomcat 6 and using the Servers functionality in Eclipse to manage it. I have a project named foobar and I'd like to change the context path so that the URLs referenced are http://localhost:8080/app instead of http://localhost:8080/foobar. I've tried everything that I can think of:

  • Updated the server.xml path value in the Context section

From

<Context docBase="foobar" path="/foobar" reloadable="true" source="org.eclipse.jst.j2ee.server:foobar"/></Host>

To

<Context docBase="foobar" path="/app" reloadable="true" source="org.eclipse.jst.j2ee.server:foobar"/></Host>

I know that I can simply rename the project, but I don't want to.

Here are my Server settings within Eclipse.

EDIT:

I also should mention that I have some db settings in the application context. I am unsure if this should be set to foobar.xml or app.xml..? Eclipse automatically creates an app.xml file in conf/Catalina/localhost, but it seems to be ignored after I make changes.

4
I have the same issue, the web-context will always be the directory name of your eclipse project whatevery you do. I think It's a bug.webpat
I think you're right, because I spent loads of time on this without being able to fix it. I wonder if it's an Eclipse bug or Tomcat bug.acvcu
While trying to extricate eclipse from our build process and reduce manual config, I noticed that it rewrites all kinds of tomcat stuff from the .location files in the .metadata folder.Erik Reppen

4 Answers

65
votes
  1. In project properties click on Web Project Settings (assuming you are in a dynamic web project.) The only configuration value there is "Context root:"
  2. change "Context root" to /app
  3. rebuild
  4. remove the project from tomcat
  5. redeploy.
4
votes

Step 1: In the project properties, click on Web Project Settings. The only configuration value there is "Context root:"

Step 2: change "Context root" to /app.

Step 3: Clean the tomcat server. enter image description here

Step 4: Click Ok button on the dialogue Box. enter image description here

Step 5: Click Yes on the next dialogue Box. enter image description here

Step 6: Rebuild your project.

0
votes

Here is an example of how I changed the context root of a web application under MyEclipse Enterprise, Version 2016 Stable 1.0, with an external Tomcat, version 6. The old context root is "cr1" and the new root is "cr2".

  1. Under the menu "Project, Properties, MyEclipse, ProjectFacets, Web", click the "Context Root" tab, click the "Config..." button, and change the "Web Context Root" to "cr2".

  2. In the "MyEclpipseExplorer" view, refactor the name of the project ("cr1"), to "cr2".

  3. Go to the "webapps" directory under Tomcat, and eliminate the directory named "cr1".

  4. Go to the directory "conf/Catalina/localhost" and remove cr1.xml.

  5. Clean and redeploy the app in MyEclipse.

0
votes

My personal experience is that the path needs to match the project name under tomcat webapps. If webapps/app1 in tomcat, then eclipse web module path needs to be /app1, otherwise there may be issue in accessing other pages, if those pages are not aligned well as relative path.