简体   繁体   中英

Changing Tomcat context path of web project in Eclipse

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.

以下是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.

  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.

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. 在此输入图像描述

Step 4: Click Ok button on the dialogue Box. 在此输入图像描述

Step 5: Click Yes on the next dialogue Box. 在此输入图像描述

Step 6: Rebuild your project.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM