You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Chris Hall <ch...@ntlworld.com> on 2007/06/21 23:51:06 UTC

Multiple Contexts from single WAR

Hi, I'm experiencing some issues with getting correct behaviour on deploying
multiple Contexts based on a single WAR. I need to do this because whilst my
application is common to multiple contexts, I need to control RemoteAddress
access to some of them via the relevant context Valve.

I have defined multiple contexts in conf/catalina/localhost/*.xml each of
which use a common docBase and this appears to create each of the webapps on
start-up.

However the servlet-mapping entries that are defined in the common
web-inf/web.xml do not appear to be applied in accessing the copied context.
For example the url-pattern which redirects to a servlet does not take
effect on the copied context definition, whereas it does apply on the webapp
that is named after the originating WAR.

I guess I could deploy multiple WARs each named differently, but that seems
to defeat what the common docBase is trying to achieve?

Is this behaviour expected? All comments gratefully received.


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Chris, to get an idea of how you can map with Apache in front of Tomcat, 
look at this link.
http://tomcat.apache.org/connectors-doc-archive/jk2/jk/aphowto.html

Its worth a read because often when the site gets bigger, you end up wanting 
to load balance, or use Apache to serve images.... so may be useful.
Remember the ROOT idea (see other post) eats up space for other web apps.
ie if you call the servlet A.... then a Web app called A is no longer a 
possibility.
If you own the server ROOT is ures, but if you hosting, they probably wont 
give it to you.

have fun



----- Original Message ----- 
From: "Chris Hall" <ch...@ntlworld.com>
To: <us...@tomcat.apache.org>
Sent: Thursday, June 21, 2007 11:51 PM
Subject: Multiple Contexts from single WAR


> Hi, I'm experiencing some issues with getting correct behaviour on 
> deploying
> multiple Contexts based on a single WAR. I need to do this because whilst 
> my
> application is common to multiple contexts, I need to control 
> RemoteAddress
> access to some of them via the relevant context Valve.
>
> I have defined multiple contexts in conf/catalina/localhost/*.xml each of
> which use a common docBase and this appears to create each of the webapps 
> on
> start-up.
>
> However the servlet-mapping entries that are defined in the common
> web-inf/web.xml do not appear to be applied in accessing the copied 
> context.
> For example the url-pattern which redirects to a servlet does not take
> effect on the copied context definition, whereas it does apply on the 
> webapp
> that is named after the originating WAR.
>
> I guess I could deploy multiple WARs each named differently, but that 
> seems
> to defeat what the common docBase is trying to achieve?
>
> Is this behaviour expected? All comments gratefully received.
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Multiple Contexts from single WAR

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Chris Hall [mailto:chrishall50@ntlworld.com] 
> Subject: RE: Multiple Contexts from single WAR
> 
> How to have a servlet mapping the same as the context name? I want
> http://localhost/<context> to invoke my servlet by default.

Pick one of the <welcome-file> names and map that to your servlet.  For
example:

    <servlet>
        <servlet-name>myServlet</servlet-name>
        <servlet-class>org.myPackage.myServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>myServlet</servlet-name>
        <url-pattern>/index.html</url-pattern>
    </servlet-mapping>

The welcome file does not have to actually exist.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Multiple Contexts from single WAR

Posted by Chris Hall <ch...@ntlworld.com>.
Guys, as the original poster of this thread I'd like to thank all concerned
for the valuable contributions.

I've learned that a single WAR can be used by creating
conf/catalina/localhost/<context>.xml files with the docBase pointing to a
fully qualified path outside of the webapps location... and that I can apply
RemoteAccess valves at that level. So in one way I'm happy, but it has
revealed another issue which I need to get round...

How to have a servlet mapping the same as the context name? I want
http://localhost/<context> to invoke my servlet by default. I've tried with
"/" and
"/<context>" as the mapping but neither work. "/*" overrides JSP servlet
which I also need. It seems all servlet mappings are relative to the
context.

Maybe I'm missing something simple?


-----Original Message-----
From: Johnny Kewl [mailto:john@kewlstuff.co.za]
Sent: 22 June 2007 18:22
To: Tomcat Users List
Subject: Re: Multiple Contexts from single WAR


Talking to David.... he's doing it yet another way.
Tomcat is certainly flexible ;)

----- Original Message -----
From: "Caldarale, Charles R" <Ch...@unisys.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Friday, June 22, 2007 5:07 PM
Subject: RE: Multiple Contexts from single WAR


> From: Johnny Kewl [mailto:john@kewlstuff.co.za]
> Subject: Re: Multiple Contexts from single WAR
>
> Even though that works, personally I would go for making
> 3 copies, rename them to whatever is wanted, then just
> drop them in.

The procedure I outlined requires only replication of the [appname].xml
file for each app - no multiple copies of the .war, no configuration, no
other fiddling around.  Why is that so hard or risky?

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Talking to David.... he's doing it yet another way.
Tomcat is certainly flexible ;)

----- Original Message ----- 
From: "Caldarale, Charles R" <Ch...@unisys.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Friday, June 22, 2007 5:07 PM
Subject: RE: Multiple Contexts from single WAR


> From: Johnny Kewl [mailto:john@kewlstuff.co.za] 
> Subject: Re: Multiple Contexts from single WAR
> 
> Even though that works, personally I would go for making
> 3 copies, rename them to whatever is wanted, then just 
> drop them in.

The procedure I outlined requires only replication of the [appname].xml
file for each app - no multiple copies of the .war, no configuration, no
other fiddling around.  Why is that so hard or risky?

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Multiple Contexts from single WAR

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Johnny Kewl [mailto:john@kewlstuff.co.za] 
> Subject: Re: Multiple Contexts from single WAR
> 
> Even though that works, personally I would go for making
> 3 copies, rename them to whatever is wanted, then just 
> drop them in.

The procedure I outlined requires only replication of the [appname].xml
file for each app - no multiple copies of the .war, no configuration, no
other fiddling around.  Why is that so hard or risky?

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Nice to know that works....
After pulling my hair out, trying to find an easier way, I have to say that 
I think Christopher Schultz really knows his Tomcat.
Even though that works, personally I would go for making 3 copies, rename 
them to whatever is wanted, then just drop them in.

Having some config that can easily get disconnected, say the next time a mod 
is done and thats forgotten.... doesnt feel good.

Its surprizing tricky.... thx


----- Original Message ----- 
From: "David kerber" <dc...@verizon.net>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Friday, June 22, 2007 2:10 PM
Subject: Re: Multiple Contexts from single WAR


>I don't know if this is how it *should* be done, but I have gotten it to 
>work by putting the context definitions in server.xml, and specifying both 
>their context base and doc base.  I never got it to work using any other 
>technique, and I tried a bunch of iterations.
>
> Dave
>
>
> Johnny Kewl wrote:
>> Charles...
>> How does the user deploy it to get it like that, thanks, we now know what 
>> cant be done, but given one WAR, how would you deploy it to 3 contexts, 
>> as 3 web apps?
>>
>> I believe the user can share it in a ROOT... if the reason for the 
>> context is merely url mapping.
>> I believe the user can deploy it via ant script which uses the built in 
>> admin tasks, ie it bypasses auto war deployment.
>>
>> How do you think it should be done?
>>
>> ----- Original Message ----- From: "Caldarale, Charles R" 
>> <Ch...@unisys.com>
>> To: "Tomcat Users List" <us...@tomcat.apache.org>
>> Sent: Friday, June 22, 2007 3:13 AM
>> Subject: RE: Multiple Contexts from single WAR
>>
>>
>>> From: Johnny Kewl [mailto:john@kewlstuff.co.za]
>>> Subject: Re: Multiple Contexts from single WAR
>>>
>>> OK... you cant do it from a WAR, the tomcat WAR deployment
>>> seems to ignore contexts and always default to the name of
>>> the WAR file.
>>
>> Not true.  When the .war is located someplace other than the <Host>
>> appBase, the name of the .xml file in conf/Catalina/[host] supplies the
>> webapp name, and the docBase attribute specifies the location -
>> completely independent of the app name.
>>
>> - Chuck
>>
>>
>> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
>> MATERIAL and is thus for use only by the intended recipient. If you
>> received this in error, please contact the sender and delete the e-mail
>> and its attachments from all computers.
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by David Smith <dn...@cornell.edu>.
Sorry, but I don't use ant.  I've switched to maven for building 
webapps.  I find it's ability to handle dependencies via standard http 
download oh so nice to work with.

What I posted allows for multiple configs from one war build -- great 
for when the logic is all the same, just need to tweak the config a 
little.  That's exactly the case with magnolia because one war build can 
be either the authoring environment or the publishing environment with 
only minor changes to it's settings.


--David

Johnny Kewl wrote:
> Hey David.... Try this.....
>
> Little bit of ant script to deploy your WAR as many times as you 
> want.... I like!
> Now if the original user had to say put 3 contexts on 5 different 
> machines... very cool!
>
> Just read the ant script.....
>
> <project name="Deployer" default="compile" basedir=".">
>
>  <path id="deployer.classpath">
>    <fileset dir="${basedir}/lib">
>      <include name="*.jar"/>
>    </fileset>
>  </path>
>
>  <taskdef resource="org/apache/catalina/ant/catalina.tasks"
>           classpathref="deployer.classpath"/>
>
>
>  <!-- point url at manager -->
>  <!-- change to username and password to Tomcat Admin -->
>  <!-- war is the path to the thing you trying to install -->
>  <!-- dont change update -->
>  <!-- path is the Context (the name you want it to be)-->
>  <!-- In Netbeans right click and run task deploy
>       then change to next context and do again and again and again
>       can deploy same war to many contexts.....
>  -->
>
>  <target name="deploy" description="Deploy web application">
>    <deploy url="http://localhost:8080/manager" username="admin" 
> password=""
>            war="D:\\DEV\\PROJECTS\\GangBangDemo\\dist\\GangBangDemo.war"
>            update="true"
>            path="/Test2"
>            />
>  </target>
>
> </project>
>  <!-- MAKE a simple java application
>       make a "lib" folder under the application folder
>       add
>        catalina-ant.jar
>        catalina-deployer.jar
>        el-api.jar
>        jasper.jar
>        jasper-el.jar
>        jsp-api.jar
>        servlet-api.jar
>        tomcat-juli.jar
>
>       They are all in your Tomcat Libs....
>
>       Note if you add 'localWar' parameter to deploy
>       you can set the destination web-app location on the "local" machine
>       So in theory you can stick wars all over your machine... not just
>       under tomcat web-apps.... but if you want deploy to another machine
>       that probably wont work over network... coz you wont even know 
> if the folder exists
>       ONLY TESTED ON Netbeans
>
>  -->
>
>
>
>
> ----- Original Message ----- From: "David kerber" <dc...@verizon.net>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Hey David.... Try this.....

Little bit of ant script to deploy your WAR as many times as you want.... I 
like!
Now if the original user had to say put 3 contexts on 5 different 
machines... very cool!

Just read the ant script.....

<project name="Deployer" default="compile" basedir=".">

  <path id="deployer.classpath">
    <fileset dir="${basedir}/lib">
      <include name="*.jar"/>
    </fileset>
  </path>

  <taskdef resource="org/apache/catalina/ant/catalina.tasks"
           classpathref="deployer.classpath"/>


  <!-- point url at manager -->
  <!-- change to username and password to Tomcat Admin -->
  <!-- war is the path to the thing you trying to install -->
  <!-- dont change update -->
  <!-- path is the Context (the name you want it to be)-->
  <!-- In Netbeans right click and run task deploy
       then change to next context and do again and again and again
       can deploy same war to many contexts.....
  -->

  <target name="deploy" description="Deploy web application">
    <deploy url="http://localhost:8080/manager" username="admin" password=""
            war="D:\\DEV\\PROJECTS\\GangBangDemo\\dist\\GangBangDemo.war"
            update="true"
            path="/Test2"
            />
  </target>

</project>
  <!-- MAKE a simple java application
       make a "lib" folder under the application folder
       add
        catalina-ant.jar
        catalina-deployer.jar
        el-api.jar
        jasper.jar
        jasper-el.jar
        jsp-api.jar
        servlet-api.jar
        tomcat-juli.jar

       They are all in your Tomcat Libs....

       Note if you add 'localWar' parameter to deploy
       you can set the destination web-app location on the "local" machine
       So in theory you can stick wars all over your machine... not just
       under tomcat web-apps.... but if you want deploy to another machine
       that probably wont work over network... coz you wont even know if the 
folder exists
       ONLY TESTED ON Netbeans

  -->




----- Original Message ----- 
From: "David kerber" <dc...@verizon.net> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by David kerber <dc...@verizon.net>.
I don't know if this is how it *should* be done, but I have gotten it to 
work by putting the context definitions in server.xml, and specifying 
both their context base and doc base.  I never got it to work using any 
other technique, and I tried a bunch of iterations.

Dave


Johnny Kewl wrote:
> Charles...
> How does the user deploy it to get it like that, thanks, we now know 
> what cant be done, but given one WAR, how would you deploy it to 3 
> contexts, as 3 web apps?
>
> I believe the user can share it in a ROOT... if the reason for the 
> context is merely url mapping.
> I believe the user can deploy it via ant script which uses the built 
> in admin tasks, ie it bypasses auto war deployment.
>
> How do you think it should be done?
>
> ----- Original Message ----- From: "Caldarale, Charles R" 
> <Ch...@unisys.com>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Friday, June 22, 2007 3:13 AM
> Subject: RE: Multiple Contexts from single WAR
>
>
>> From: Johnny Kewl [mailto:john@kewlstuff.co.za]
>> Subject: Re: Multiple Contexts from single WAR
>>
>> OK... you cant do it from a WAR, the tomcat WAR deployment
>> seems to ignore contexts and always default to the name of
>> the WAR file.
>
> Not true.  When the .war is located someplace other than the <Host>
> appBase, the name of the .xml file in conf/Catalina/[host] supplies the
> webapp name, and the docBase attribute specifies the location -
> completely independent of the app name.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Multiple Contexts from single WAR

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Johnny Kewl [mailto:john@kewlstuff.co.za] 
> Subject: Re: Multiple Contexts from single WAR
> 
> How does the user deploy it to get it like that, thanks,
> we now know what cant be done, but given one WAR, how 
> would you deploy it to 3 contexts, as 3 web apps?

Either do it manually (as I did, for verification), or write a custom
script - one that creates the multiple <appname>.xml files in
conf/Catalina/[host].  All of the <Context> attributes remain the same;
only the name of the .xml file changes.

This has nothing to do with the default app, so ROOT doesn't come into
play.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Multiple Contexts from single WAR

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: David Smith [mailto:dns4@cornell.edu] 
> Subject: Re: Multiple Contexts from single WAR
> 
> I don't know of any way to make one war deploy as three separate 
> contexts.

I already described the required procedure; here it is again:

1) The .war file must NOT go into the <Host> appBase directory (usually
webapps).

2) There must NOT be a path attribute in the <Context> (it would be
ignored, anyway).

3) Create a <Context> element in some file (not META-INF/context.xml)
with a docBase attribute specifying the absolute file system path of the
.war file.

4) Replicate the above file as many times as needed as [appname].xml in
conf/Catalina/[host].

Note that there are only two active steps, since the first two are
things NOT to do.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by David Smith <dn...@cornell.edu>.
I don't know of any way to make one war deploy as three separate 
contexts.  I do know you could have a ServletContextListener look at the 
context name and then read some config files dependant on the context 
name.  That's how Magnolia CMS allows for one source war to be deployed 
in separate roles.  Just make a copy of the war, rename it to 
newContextName.war and deploy it.  One source build environment -> 
multiple deployements.

--David

Johnny Kewl wrote:
> Charles...
> How does the user deploy it to get it like that, thanks, we now know 
> what cant be done, but given one WAR, how would you deploy it to 3 
> contexts, as 3 web apps?
>
> I believe the user can share it in a ROOT... if the reason for the 
> context is merely url mapping.
> I believe the user can deploy it via ant script which uses the built 
> in admin tasks, ie it bypasses auto war deployment.
>
> How do you think it should be done?
>
> ----- Original Message ----- From: "Caldarale, Charles R" 
> <Ch...@unisys.com>
> To: "Tomcat Users List" <us...@tomcat.apache.org>
> Sent: Friday, June 22, 2007 3:13 AM
> Subject: RE: Multiple Contexts from single WAR
>
>
>> From: Johnny Kewl [mailto:john@kewlstuff.co.za]
>> Subject: Re: Multiple Contexts from single WAR
>>
>> OK... you cant do it from a WAR, the tomcat WAR deployment
>> seems to ignore contexts and always default to the name of
>> the WAR file.
>
> Not true.  When the .war is located someplace other than the <Host>
> appBase, the name of the .xml file in conf/Catalina/[host] supplies the
> webapp name, and the docBase attribute specifies the location -
> completely independent of the app name.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Charles...
How does the user deploy it to get it like that, thanks, we now know what 
cant be done, but given one WAR, how would you deploy it to 3 contexts, as 3 
web apps?

I believe the user can share it in a ROOT... if the reason for the context 
is merely url mapping.
I believe the user can deploy it via ant script which uses the built in 
admin tasks, ie it bypasses auto war deployment.

How do you think it should be done?

----- Original Message ----- 
From: "Caldarale, Charles R" <Ch...@unisys.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Friday, June 22, 2007 3:13 AM
Subject: RE: Multiple Contexts from single WAR


> From: Johnny Kewl [mailto:john@kewlstuff.co.za]
> Subject: Re: Multiple Contexts from single WAR
>
> OK... you cant do it from a WAR, the tomcat WAR deployment
> seems to ignore contexts and always default to the name of
> the WAR file.

Not true.  When the .war is located someplace other than the <Host>
appBase, the name of the .xml file in conf/Catalina/[host] supplies the
webapp name, and the docBase attribute specifies the location -
completely independent of the app name.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Ok thanks Charles

----- Original Message ----- 
From: "Caldarale, Charles R" <Ch...@unisys.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Friday, June 22, 2007 4:02 PM
Subject: RE: Multiple Contexts from single WAR


> From: Johnny Kewl [mailto:john@kewlstuff.co.za] 
> Subject: Re: Multiple Contexts from single WAR
> 
> <Context path="/TheOneIWant"/>
> 
> Compile it and drop that WAR into Tomcats webapp (auto deploy)
> 
> The context will be changed to TEST.... will it not?
> Yes it does describe the thing in conf/Catalina/[host] 
> but its not the one the user put in....
> 
> Please explain why this is not true?

The above is true, but has nothing to do with the procedure described
yesterday.

1) The .war file must NOT go into the <Host> appBase directory (usually
webapps).

2) There must NOT be a path attribute in the <Context> (it would be
ignored, anyway).

3) Create a <Context> element in some file (not META-INF/context.xml)
with a docBase attribute specifying the absolute file system path of the
.war file.

4) Replicate the above file as many times as needed as [appname].xml in
conf/Catalina/[host].

You're done.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Multiple Contexts from single WAR

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Johnny Kewl [mailto:john@kewlstuff.co.za] 
> Subject: Re: Multiple Contexts from single WAR
> 
> <Context path="/TheOneIWant"/>
> 
> Compile it and drop that WAR into Tomcats webapp (auto deploy)
> 
> The context will be changed to TEST.... will it not?
> Yes it does describe the thing in conf/Catalina/[host] 
> but its not the one the user put in....
> 
> Please explain why this is not true?

The above is true, but has nothing to do with the procedure described
yesterday.

1) The .war file must NOT go into the <Host> appBase directory (usually
webapps).

2) There must NOT be a path attribute in the <Context> (it would be
ignored, anyway).

3) Create a <Context> element in some file (not META-INF/context.xml)
with a docBase attribute specifying the absolute file system path of the
.war file.

4) Replicate the above file as many times as needed as [appname].xml in
conf/Catalina/[host].

You're done.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Johnny,

Johnny Kewl wrote:
> <Context path="/TheOneIWant"/>
> 
> Compile it and drop that WAR into Tomcats webapp (auto deploy)

They're not talking about auto-deploy. I think this part is confusing you.

You're right: auto-deploy uses the name of the WAR file for the context
path (unless the WAR file name and <Context path="..."> conflict, at
which point I think nothing works, given the number of questions on the
list about this).

Since the OP is using server.xml to deploy these <Context>s
individually, the "WAR filename dictates the context path" feature
doesn't apply.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGe72v9CaO5/Lv0PARAu/KAKCcp2GD2XaWctW46r4C6w5FHM5l1wCfXtJ5
wNiIlgkCO+Wtx3JMJujKxRM=
=CmdL
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Ok, maybe I'm missing something, please show us how this works....
Make a Web App with the name TEST
make the context path

<Context path="/TheOneIWant"/>

Compile it and drop that WAR into Tomcats webapp (auto deploy)

The context will be changed to TEST.... will it not?
Yes it does describe the thing in conf/Catalina/[host] 
but its not the one the user put in....

Please explain why this is not true?

----- Original Message ----- 
From: "Caldarale, Charles R" <Ch...@unisys.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Friday, June 22, 2007 3:13 AM
Subject: RE: Multiple Contexts from single WAR


> From: Johnny Kewl [mailto:john@kewlstuff.co.za] 
> Subject: Re: Multiple Contexts from single WAR
> 
> OK... you cant do it from a WAR, the tomcat WAR deployment 
> seems to ignore contexts and always default to the name of
> the WAR file.

Not true.  When the .war is located someplace other than the <Host>
appBase, the name of the .xml file in conf/Catalina/[host] supplies the
webapp name, and the docBase attribute specifies the location -
completely independent of the app name.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Multiple Contexts from single WAR

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Johnny Kewl [mailto:john@kewlstuff.co.za] 
> Subject: Re: Multiple Contexts from single WAR
> 
> OK... you cant do it from a WAR, the tomcat WAR deployment 
> seems to ignore contexts and always default to the name of
> the WAR file.

Not true.  When the .war is located someplace other than the <Host>
appBase, the name of the .xml file in conf/Catalina/[host] supplies the
webapp name, and the docBase attribute specifies the location -
completely independent of the app name.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Apologies....
OK... you cant do it from a WAR, the tomcat WAR deployment seems to ignore 
contexts and always default to the name of the WAR file. Try it with just 
one context and you'll see the behaviour.

But you can do it from the standalone deployer... ie deploy the war file to 
any context you want.... it will require a little ant script.

Why didnt you just say so ;) ...  bed time for me.


----- Original Message ----- 
From: "Caldarale, Charles R" <Ch...@unisys.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Friday, June 22, 2007 2:08 AM
Subject: RE: Multiple Contexts from single WAR


> From: Johnny Kewl [mailto:john@kewlstuff.co.za]
> Subject: Re: Multiple Contexts from single WAR
>
> Chris, dont think you can... just so I understand it.... you thinking
> http://localhost:8080/A
> http://localhost:8080/B
> http://localhost:8080/C
> must all map to one web-app, say WebApp A.... that I dont
> think is possible

No, that's not what he's asking for.  The original question was about
multiple webapps deployed from the same .war file.  Each would run
independently, once loaded.  Nothing to do with URL mappings, and
throwing httpd in front would only add complexity and have no effect on
the original issue.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Multiple Contexts from single WAR

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Johnny Kewl [mailto:john@kewlstuff.co.za] 
> Subject: Re: Multiple Contexts from single WAR
> 
> Chris, dont think you can... just so I understand it.... you thinking
> http://localhost:8080/A
> http://localhost:8080/B
> http://localhost:8080/C
> must all map to one web-app, say WebApp A.... that I dont 
> think is possible

No, that's not what he's asking for.  The original question was about
multiple webapps deployed from the same .war file.  Each would run
independently, once loaded.  Nothing to do with URL mappings, and
throwing httpd in front would only add complexity and have no effect on
the original issue.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Johnny Kewl <jo...@kewlstuff.co.za>.
Chris, dont think you can... just so I understand it.... you thinking

http://localhost:8080/A


http://localhost:8080/B


http://localhost:8080/C

must all map to one web-app, say WebApp A.... that I dont think is possible

But if you not using ROOT for anything else other than Welcome to Tomcat, 
then you can try this...

You rename your WebApp to ROOT
Make the context path ""  (nothing)

And then those A,B and C's no longer represent Web Apps, they represent 
servlets.
You can MAP away merrily in web.xml

ie /C  to servlet A
/B to servlet A

/C/doSomething  to servlet E

etc etc etc.....

maybe.... depends wot you doing I guess, and if ROOT is yours to take.

otherwise.... little webapps that redirect is another possibility.
Apache in front could probably also map any URI to just about anything.

Anyway.... hope more ideas come forward for you...

----- Original Message ----- 
From: "Chris Hall" <ch...@ntlworld.com>
To: <us...@tomcat.apache.org>
Sent: Thursday, June 21, 2007 11:51 PM
Subject: Multiple Contexts from single WAR


> Hi, I'm experiencing some issues with getting correct behaviour on 
> deploying
> multiple Contexts based on a single WAR. I need to do this because whilst 
> my
> application is common to multiple contexts, I need to control 
> RemoteAddress
> access to some of them via the relevant context Valve.
>
> I have defined multiple contexts in conf/catalina/localhost/*.xml each of
> which use a common docBase and this appears to create each of the webapps 
> on
> start-up.
>
> However the servlet-mapping entries that are defined in the common
> web-inf/web.xml do not appear to be applied in accessing the copied 
> context.
> For example the url-pattern which redirects to a servlet does not take
> effect on the copied context definition, whereas it does apply on the 
> webapp
> that is named after the originating WAR.
>
> I guess I could deploy multiple WARs each named differently, but that 
> seems
> to defeat what the common docBase is trying to achieve?
>
> Is this behaviour expected? All comments gratefully received.
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Multiple Contexts from single WAR

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Chris Hall [mailto:chrishall50@ntlworld.com] 
> Subject: Multiple Contexts from single WAR
> 
> I have defined multiple contexts in 
> conf/catalina/localhost/*.xml each of which use 
> a common docBase and this appears to create each
> of the webapps on start-up.

If you're going to play this game, make sure the webapp is not installed
under the <Host> appBase directory - doing so may cause a bit of
confusion.

> the servlet-mapping entries that are defined in
> the common web-inf/web.xml

I hope you mean WEB-INF/web.xml, since case matters.

> the url-pattern which redirects to a servlet does
> not take effect on the copied context definition

Is the app using hard-coded URLs anywhere?

You didn't bother to mention what version of Tomcat you're using.
Assuming you're on a reasonably current one, you could try enabling the
AccessLogValve for the <Host>.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Multiple Contexts from single WAR

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris,

Chris Hall wrote:
> Hi, I'm experiencing some issues with getting correct behaviour on deploying
> multiple Contexts based on a single WAR. I need to do this because whilst my
> application is common to multiple contexts, I need to control RemoteAddress
> access to some of them via the relevant context Valve.

I don't buy it. What is stopping you from using one WAR file per webapp?

> I have defined multiple contexts in conf/catalina/localhost/*.xml each of
> which use a common docBase and this appears to create each of the webapps on
> start-up.

I don't see why this wouldn't work, but I also don't understand why it
would ever be desirable.

> However the servlet-mapping entries that are defined in the common
> web-inf/web.xml do not appear to be applied in accessing the copied context.

What do you mean, the "common" web.xml? Also, you're sure you have that
as "WEB-INF", not "web-inf", right?

> For example the url-pattern which redirects to a servlet does not take
> effect on the copied context definition, whereas it does apply on the webapp
> that is named after the originating WAR.

So you're basically saying that these "extra" contexts don't appear to
deploy at all? Or do they not deploy properly? If you can't use your
servlets, why do you think that anything is working at all?

> I guess I could deploy multiple WARs each named differently, but that seems
> to defeat what the common docBase is trying to achieve?

Since it doesn't appear to be working, you should try the multiple-WARs
approach and see if /that/ works. If multiple WAR files don't work, then
you have something else wrong in your configuration, and your
multiply-deployed-WAR strategy might still be viable.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGevgJ9CaO5/Lv0PARAnMvAKCEWbUSj9IPRvtux8zUZ6NVtzYZsQCgkop+
cn+smsqQ8UYMHZmajuQH9sQ=
=5g7s
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org