2

I have my web application whose name is myApp.war. I copy my war file in $CATALINA_BASE/webapps. Now I can open my site using the URL:

http://localhost:8080/myApp/

However I want to change the path of my application (for example: newName), so I add a file ROOT.xml in $CATALINA_BASE/conf/Catalina/localhost.

Here is the code :

<Context docBase="myApp" path="/newName" debug="0" reloadable="true"/>

Now I use the new URL:

http://localhost:8080/newName/ 

but it doesn't work.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
stevey
  • 1,137
  • 4
  • 21
  • 30

3 Answers3

3

Add the line below in your server.xml:

<Context docBase="myApp" path="/newName" debug="0" reloadable="true"/>

Like:

<Host>
  .
  .
  .
  <Context docBase="myApp" path="/newName" debug="0" reloadable="true"/>
</Host>
</Engine>
</Service>
</Server>

I would suggest another approach by using the Apache web server. Edit httpd.conf and write:

ProxyPass /newName http://localhost:8080/myApp
ProxyPassReverse /newName http://localhost:8080/myApp

You can access your app by http://localhost/newName.

Note: Apache runs on port 80 so you don't need to give the port number after localhost while accessing.

wxs
  • 288
  • 3
  • 18
neonleo
  • 194
  • 1
  • 2
  • but in the document of Tomcat it says : For Tomcat 6, unlike Tomcat 4.x, it is NOT recommended to place elements directly in the server.xml file. This is because it makes modifying the Context configuration more invasive since the main conf/server.xml file cannot be reloaded without restarting Tomcat. @neonleo – stevey Mar 08 '13 at 13:16
  • Hi marssteve, because of this reason, i have provided a solution by using apache web server. You can paste two line of code that i have written and access by the mentioned URL. Any xml configuration change in server would ask for restart to take effect. – neonleo Mar 08 '13 at 13:34
1

Try renaming ROOT.xml to newName.xml and put it in "$CATALINA_BASE/conf/Catalina/localhost" folder. Tomcat tries to find the same appName and xml file. I hope it was useful for your request.

Tomcat 6 Documentation - Context

See Introduction title: "[...]In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml extension) will be used as the context path[...]"

Told me if it works, Regards.

Sorry about my english!! ;)

0

Have you added NewName directory in the tomcat webapps path and copied the content to it? I hope that should resolve your issue.

PSR
  • 31
  • 3