You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Harri Pesonen <ha...@sinch.com> on 2022/04/01 14:59:44 UTC

Two context paths to same application

Hello,

while reading the documentation in
https://tomcat.apache.org/tomcat-8.5-doc/config/context.html#Naming
it is not clear to me how to achieve the following:

Have one WAR file with corresponding directory, for example:

app#1.war => app#1 (directory) => /app/1 (context path)

But have another context path pointing to same application:

/app/latest (context path) => app#1 (directory)

I tried adding <Context> to server.xml inside <Host> like:

<Context docBase="app#1 " path="/app/latest"/>

But Tomcat created another directory app#latest from this, and copied app#1 there.
I would like to avoid having duplicate directories.

Doc says that:
* To define multiple contexts that use a single WAR file or directory, use one of the options described in the Naming section above for creating a Context that has a path that is not related to the base file name.
* If you want to deploy a WAR file or a directory using a context path that is not related to the base file name then one of the following options must be used to prevent double-deployment:
** Disable autoDeploy and deployOnStartup and define all Contexts in server.xml
** Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.

Don't quite understand what to do.
Do I need add <Context> also to the existing application:

<Context docBase="app#1 " path="/app/1"/>

Or what does "define all Contexts in server.xml" mean?
And what does the second option (Locate the WAR...) mean?

Thanks,

-Harri


Re: Two context paths to same application

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Harri,

On 4/5/22 13:29, Harri Pesonen wrote:
> Ok, it is a bit disappointing that Tomcat does not support this in
> standard webapps folder.
> 
> But I found an easy workaround: create Windows junction app#latest
> that points to app#1 folder (both in webapps).

You are doing something which is definitely not recommended. Expanding
your WAR file twice on the disk really shouldn't be a big deal. I would
challenge your requirement for having a single directory for these two
contexts. There is no memory savings whatsoever by doing this. You only
save disk space and perhaps the time-to-expand the WAR file (which is
done only once per deployment).

Thanks,
-chris

> -----Original Message----- From: Mark Thomas <ma...@apache.org> Sent:
> perjantai 1. huhtikuuta 2022 18.46 To: users@tomcat.apache.org 
> Subject: Re: Two context paths to same application
> 
> On 01/04/2022 15:59, Harri Pesonen wrote:
>> Hello,
>> 
>> while reading the documentation in 
>> https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftomc
>>
>> 
at.apache.org%2Ftomcat-8.5-doc%2Fconfig%2Fcontext.html%23Naming&amp;da
>> ta=04%7C01%7Charri.pesonen%40sinch.com%7Cdac1869da5b046b4f23e08da13f6c
>>
>> 
c02%7C3b518aae89214a7b8497619d756ce20e%7C0%7C0%7C637844248015649619%7C
>> Unknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1h
>>
>> 
aWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=vHZmEqMaCuKbja9GN1vHfCgD5pEKVLzYsb
>> L21ZaJtvg%3D&amp;reserved=0 it is not clear to me how to achieve
>> the following:
>> 
>> Have one WAR file with corresponding directory, for example:
>> 
>> app#1.war => app#1 (directory) => /app/1 (context path)
>> 
>> But have another context path pointing to same application:
>> 
>> /app/latest (context path) => app#1 (directory)
>> 
>> I tried adding <Context> to server.xml inside <Host> like:
>> 
>> <Context docBase="app#1 " path="/app/latest"/>
>> 
>> But Tomcat created another directory app#latest from this, and
>> copied app#1 there. I would like to avoid having duplicate
>> directories.
>> 
>> Doc says that: * To define multiple contexts that use a single WAR
>> file or directory, use one of the options described in the Naming
>> section above for creating a Context that has a path that is not
>> related to the base file name. * If you want to deploy a WAR file
>> or a directory using a context path that is not related to the base
>> file name then one of the following options must be used to prevent
>> double-deployment: ** Disable autoDeploy and deployOnStartup and
>> define all Contexts in server.xml ** Locate the WAR and/or
>> directory outside of the Host's appBase and use a context.xml file
>> with a docBase attribute to define it.
>> 
>> Don't quite understand what to do. Do I need add <Context> also to
>> the existing application:
>> 
>> <Context docBase="app#1 " path="/app/1"/>
>> 
>> Or what does "define all Contexts in server.xml" mean? And what
>> does the second option (Locate the WAR...) mean?
> 
> The key part is you need to locate the docBase (the web application
> WAR or directory) NOT under the appBase ($CATALINA_BASE/webapps). So
> something like this:
> 
> /opt/webapps/myapp-1
> 
> and then under $CATALINA_BASE/conf/Catlaina/localhost you'll need two
> context files:
> 
> myapp#1.xml <Context docBase="/opt/webapps/myapp-1" />
> 
> myapp#latest.xml <Context docBase="/opt/webapps/myapp-1" />
> 
> HTH,
> 
> MarK
> 
> ---------------------------------------------------------------------
>
> 
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> ---------------------------------------------------------------------
>
> 
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

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


RE: Two context paths to same application

Posted by Harri Pesonen <ha...@sinch.com>.
Ok, it is a bit disappointing that Tomcat does not support this in standard webapps folder.
But I found an easy workaround: create Windows junction app#latest that points to app#1 folder (both in webapps).

-Harri

-----Original Message-----
From: Mark Thomas <ma...@apache.org> 
Sent: perjantai 1. huhtikuuta 2022 18.46
To: users@tomcat.apache.org
Subject: Re: Two context paths to same application

On 01/04/2022 15:59, Harri Pesonen wrote:
> Hello,
> 
> while reading the documentation in
> https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftomc
> at.apache.org%2Ftomcat-8.5-doc%2Fconfig%2Fcontext.html%23Naming&amp;da
> ta=04%7C01%7Charri.pesonen%40sinch.com%7Cdac1869da5b046b4f23e08da13f6c
> c02%7C3b518aae89214a7b8497619d756ce20e%7C0%7C0%7C637844248015649619%7C
> Unknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1h
> aWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=vHZmEqMaCuKbja9GN1vHfCgD5pEKVLzYsb
> L21ZaJtvg%3D&amp;reserved=0 it is not clear to me how to achieve the 
> following:
> 
> Have one WAR file with corresponding directory, for example:
> 
> app#1.war => app#1 (directory) => /app/1 (context path)
> 
> But have another context path pointing to same application:
> 
> /app/latest (context path) => app#1 (directory)
> 
> I tried adding <Context> to server.xml inside <Host> like:
> 
> <Context docBase="app#1 " path="/app/latest"/>
> 
> But Tomcat created another directory app#latest from this, and copied app#1 there.
> I would like to avoid having duplicate directories.
> 
> Doc says that:
> * To define multiple contexts that use a single WAR file or directory, use one of the options described in the Naming section above for creating a Context that has a path that is not related to the base file name.
> * If you want to deploy a WAR file or a directory using a context path that is not related to the base file name then one of the following options must be used to prevent double-deployment:
> ** Disable autoDeploy and deployOnStartup and define all Contexts in 
> server.xml
> ** Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.
> 
> Don't quite understand what to do.
> Do I need add <Context> also to the existing application:
> 
> <Context docBase="app#1 " path="/app/1"/>
> 
> Or what does "define all Contexts in server.xml" mean?
> And what does the second option (Locate the WAR...) mean?

The key part is you need to locate the docBase (the web application WAR or directory) NOT under the appBase ($CATALINA_BASE/webapps). So something like this:

/opt/webapps/myapp-1

and then under $CATALINA_BASE/conf/Catlaina/localhost you'll need two context files:

myapp#1.xml
<Context docBase="/opt/webapps/myapp-1" />

myapp#latest.xml
<Context docBase="/opt/webapps/myapp-1" />

HTH,

MarK

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


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


Re: Two context paths to same application

Posted by Mark Thomas <ma...@apache.org>.
On 01/04/2022 15:59, Harri Pesonen wrote:
> Hello,
> 
> while reading the documentation in
> https://tomcat.apache.org/tomcat-8.5-doc/config/context.html#Naming
> it is not clear to me how to achieve the following:
> 
> Have one WAR file with corresponding directory, for example:
> 
> app#1.war => app#1 (directory) => /app/1 (context path)
> 
> But have another context path pointing to same application:
> 
> /app/latest (context path) => app#1 (directory)
> 
> I tried adding <Context> to server.xml inside <Host> like:
> 
> <Context docBase="app#1 " path="/app/latest"/>
> 
> But Tomcat created another directory app#latest from this, and copied app#1 there.
> I would like to avoid having duplicate directories.
> 
> Doc says that:
> * To define multiple contexts that use a single WAR file or directory, use one of the options described in the Naming section above for creating a Context that has a path that is not related to the base file name.
> * If you want to deploy a WAR file or a directory using a context path that is not related to the base file name then one of the following options must be used to prevent double-deployment:
> ** Disable autoDeploy and deployOnStartup and define all Contexts in server.xml
> ** Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.
> 
> Don't quite understand what to do.
> Do I need add <Context> also to the existing application:
> 
> <Context docBase="app#1 " path="/app/1"/>
> 
> Or what does "define all Contexts in server.xml" mean?
> And what does the second option (Locate the WAR...) mean?

The key part is you need to locate the docBase (the web application WAR 
or directory) NOT under the appBase ($CATALINA_BASE/webapps). So 
something like this:

/opt/webapps/myapp-1

and then under $CATALINA_BASE/conf/Catlaina/localhost you'll need two 
context files:

myapp#1.xml
<Context docBase="/opt/webapps/myapp-1" />

myapp#latest.xml
<Context docBase="/opt/webapps/myapp-1" />

HTH,

MarK

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