The moose likes Tomcat and the fly likes tomcat 6 - how to define context root name diff than WAR file name Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Products » Tomcat
Reply Bookmark "tomcat 6 - how to define context root name diff than WAR file name" Watch "tomcat 6 - how to define context root name diff than WAR file name" New topic
Author

tomcat 6 - how to define context root name diff than WAR file name

sush dod
Greenhorn

Joined: Nov 26, 2005
Posts: 4
HI guys i am using TOMCAT 6 to deploy a struts based application WAR file.
my problem is my WAR file name is aaa.0.0.1d.WAR in dev aaa.0.0.1s.WAR in stage and aaa.0.0.1p in prod environment.
for dev WAR i need to set the context root as reporting so that my request URL would be
http://localhost:8090/reporting/getReport.do
i tried creating a XML file as aaa.0.0.1d.xml and deployed in the CATALINA_HOME/conf/Catalina/localhost/ directory
and the content of the file is

<?xml version="1.0" encoding="UTF-8"?>
<!-- Context fragment for deploying the build-demo application

-->
<Context path="/reporting" docBase="..\webapps\aaa.0.0.1d.war" />

but as my WAR file name is aaa.0.0.1d.WAR i cant use above mentioned request URL.
if i use the request URL as
http://localhost:8090/aaa.0.0.1d/getReport.do then it works fine.
so in short i need to define a context root which is diffrent than my application WAR name.
can anybody tell me how can i do this?
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3562

First off you should use relative path names, then you wouldn't even need to worry about what the base URL is. Second, it sounds like your configuration is wrong, the WAR name does not need to be part of the URL. Are you putting the information you want in the server config or the WEB-INF/web.xml file?


My Blog: Down Home Country Coding with Scott Selikoff
sush dod
Greenhorn

Joined: Nov 26, 2005
Posts: 4
no i am not writing nything in the server.xml and even in web.xml
my web.xml looks as below

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
</taglib>

<taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>


what do you mean by my configuration is wrong.
i can access my application using the URL
http://loalhost:8090/aaa.0.0.1d/....
can you tell me how do you set the relative path in the application specific xml file?
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3562

Originally posted by sush dod:
no i am not writing nything in the server.xml and even in web.xml


Stop right there. That's your problem. Context path is controlled by one of these files.

And in the words of a friend of mine "Not writing nything"? Ok first nothing is misspelled but even still "no i am not writing nothing" ... such bad grammar.
[ August 19, 2008: Message edited by: Scott Selikoff ]
Karel Vervaeke
Greenhorn

Joined: Jul 20, 2004
Posts: 4
Originally posted by Scott Selikoff:

And in the words of a friend of mine "Not writing nything"? Ok first nothing is misspelled but even still "no i am not writing nothing" ... such bad grammar.
[ August 19, 2008: Message edited by: Scott Selikoff ]


The poster meant to write "anything". As a typo, "any -> ny" makes much more sense than "not -> nyt"
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3562

Karel, if you're going to nitpick at least provide useful information to the original poster when you do as I did.
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 48621

Actually, the current accepted way to add a new context is through a context file in conf/Catalina rather than in server.xml. See the Tomcat docs.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Narendra shah
Ranch Hand

Joined: Feb 28, 2007
Posts: 49
sush dod wrote:HI guys i am using TOMCAT 6 to deploy a struts based application WAR file.
my problem is my WAR file name is aaa.0.0.1d.WAR in dev aaa.0.0.1s.WAR in stage and aaa.0.0.1p in prod environment.
for dev WAR i need to set the context root as reporting so that my request URL would be
http://localhost:8090/reporting/getReport.do
i tried creating a XML file as aaa.0.0.1d.xml and deployed in the CATALINA_HOME/conf/Catalina/localhost/ directory
and the content of the file is

<?xml version="1.0" encoding="UTF-8"?>
<!-- Context fragment for deploying the build-demo application

-->
<Context path="/reporting" docBase="..\webapps\aaa.0.0.1d.war" />

but as my WAR file name is aaa.0.0.1d.WAR i cant use above mentioned request URL.
if i use the request URL as
http://localhost:8090/aaa.0.0.1d/getReport.do then it works fine.
so in short i need to define a context root which is diffrent than my application WAR name.
can anybody tell me how can i do this?


If i not understood you wrong then you want to set your root web application to your default web application. meaning when you open http://localhost:8090/ then your application will be loaded. For doing this you need to just add folowing tag in server.xml tag within host tag.



refer : how to configure root application Tomcat

This message was edited 1 time. Last update was at by Narendra shah



Narendra Shah -- SCJP 5
Stas Sokolov
Ranch Hand

Joined: Apr 13, 2004
Posts: 111

sush dod wrote:
so in short i need to define a context root which is diffrent than my application WAR name.
can anybody tell me how can i do this?


Did you try to edit server.xml ? Put something like this at the very end


I tried it with supplied docs folder. It worked fine for me.


http://localhost:8221/ZZZ/ - this is my baby


Good luck for yourself.
suhana mathur
Greenhorn

Joined: Dec 02, 2011
Posts: 1
Didn't adding <Context docBase="docs" path="/ZZZ" />
to server.xml deploy your application twice ? I am facing the same issue.I need the context path to be different to my WAR name.
But editing server.xml is not recommended by Tomcat and even if you do it the war is deployed twice.
 
 
subject: tomcat 6 - how to define context root name diff than WAR file name
 
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture