How to change context root of a dynamic web projec

2018-12-31 15:25发布

I have developed a dynamic web project in Eclipse. Now I can access it through my browser using the following URL:

http://localhost:8080/MyDynamicWebApp

Now I want to change the access URL to

http://localhost:8080/app

I changed the context root from the project "Properties | Web Project Settings | Context Root".

But it is not working. The web app still has the access URL as earlier. I have re-deployed the application on Tomcat, re-started the Tomcat and have done everything that should be done, but the access URL is the same as earlier.

I found that there were no server.xml file attached with the WAR file. Then how the Tomcat is determining that the context root of my web app is /MyDynamicWebApp and is allowing me to access the application through that URL?

12条回答
临风纵饮
2楼-- · 2018-12-31 15:44

I tried out solution suggested by Russ Bateman Here in the post

http://localhost:8080/Myapp to http://localhost:8080/somepath/Myapp

But Didnt worked for me as I needed to have a *.war file that can hold the config and not the individual instance of server on my localmachine.

Reference

In order to do that I need jboss-web.xml placed in WEB-INF

<?xml version="1.0" encoding="UTF-8"?>
 <!--
Copyright (c) 2008 Object Computing, Inc.
All rights reserved.
-->
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 4.2//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">

  <jboss-web>
  <context-root>somepath/Myapp</context-root>
  </jboss-web>
查看更多
回忆,回不去的记忆
3楼-- · 2018-12-31 15:49

I just wanted to add that if you don't want your application name in the root context at all, you and just put "/" (no quotes, just the forward slash) in the Eclipse --> Web Project Settings --> Context Root entry

That will deploy the webapp to just http://localhost:8080/

Of course, this will cause problems with other webapps you try to run on the server, so heads up with that.

Took me forever to piece that together... so even though this post is 8 years old, hopefully this will still help someone!

查看更多
听够珍惜
4楼-- · 2018-12-31 15:50

If the project is maven, change the "finalName" in pom.xml and Update Project as Maven.This worked for me.

查看更多
妖精总统
5楼-- · 2018-12-31 15:52

Setting the path to nothing in the Eclipse web modules edit dialog enabled me to access the project without any path component in the URL (i.e. ROOT)

You can reach the web modules edit dialog by pressing F3 if you select Tomcat in the "Servers" view or by double clicking on it.

Some screenshots:

查看更多
深知你不懂我心
6楼-- · 2018-12-31 15:55

Apache tomcat keeps the project context path in server.xml path. For each web project on Eclipse, there is tag from there you can change it.
Suppose, there are two or three project deployed on server. For each one context path is stored in . This tag is located on server.xml file within Server created on eclipse.

I have one project for there on context root path in server is:

<Context docBase="Test" path="/test" reloadable="true" source="org.eclipse.jst.jee.server:Test1"/>

This path represents context path of your web application. By changing this path, your web app context path will change.

查看更多
不流泪的眼
7楼-- · 2018-12-31 15:55

If using eclipse to deploy your application . We can use this maven plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.10</version>
    <configuration>
        <wtpversion>2.0</wtpversion>
        <wtpContextName>newContextroot</wtpContextName>
    </configuration>
</plugin>

now go to your project root folder and open cmd prompt at that location type this command :

mvn eclipse:eclipse -Dwtpversion=2.0

You may need to restart eclipse , or in server view delete server and create agian to see affect. I wonder this exercise make sense in real life but works.

查看更多
登录 后发表回答