tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Terence M. Bandoian" <tere...@tmbsw.com>
Subject Re: Host appBase vs Context docBase
Date Mon, 07 Jul 2014 16:54:23 GMT
On 7/5/2014 1:38 PM, Igal @ getRailo.org wrote:
>> What version of Tomcat are you using?
> I've been using Tomcat 6 and 7 for a while, and now running Tomcat 8.
>
>> it is recommended that <Context> elements not be placed directly in 
>> server.xml
> I know, but it is much easier for me to edit a single file, server.xml 
> then deploy all the other files.  I'm looking to keep the deployment 
> process as simple as possible.
>
>> you shouldn't need the empty directory. I've used an absolute path 
>> for the <Host> appBase attribute with relative paths for <Context> 
>> docBase attributes in Tomcat 6 and 7 without any problems.
> when I try that then "webapps" is used by default.  if a request is 
> made for a file that exists in webapps, e.g. index.jsp and does not 
> exist in my application's folder, then it is served from webapps and I 
> don't want that.
>
>> are you sure you want "/" for the <Context> path attribute in the 
>> first example above?
> it was my understanding that "" and "/" are the same here.  "/" reads 
> more clearly to me as the "root" directory so I prefer to use that.
>
> *after reading your email and testing it, however, I noticed that if I 
> omit the Host/appBase and use an empty-string for the 
> Context/docBase/path it works as intended, so maybe that's what I was 
> doing wrong?  is that the best practice?*
>
> <Host name="Site1" unpackWARs="false" autoDeploy="false">
>   <Context path="" docBase="D:/www/site1" />
>   <Context path="/virtualdir" docBase="D:/www/shared/virtualdir" />
> </Host>
>
> ?
>
> thank you both for your responses,
>
>
> Igal
>
>
> On 7/5/2014 9:48 AM, Terence M. Bandoian wrote:
>> On 7/4/2014 9:04 PM, Igal @ getRailo.org wrote:
>>> I'm a little confused about the Host appBase attribute.
>>>
>>> Let's say that my website resides in D:\www\site1
>>>
>>> I don't like using {Tomcat}/webapps so I don't want to have it as a 
>>> base directory for websites.  What I've been doing so far is create 
>>> an empty folder alongside "webapps", named "empty", and use it as 
>>> appBase, e.g.
>>>
>>> <Host name="Site1" appBase="empty" unpackWARs="false" 
>>> autoDeploy="false">
>>>   <!-- this works but what's the deal with appBase? !-->
>>>   <Context path="/" docBase="D:/www/site1" />
>>> </Host>
>>>
>>> But it feels like I'm doing something wrong.  I expect this to work, 
>>> but it doesn't:
>>>
>>> <Host name="Site1" appBase="D:/www/site1" unpackWARs="false" 
>>> autoDeploy="false">
>>>   <!-- this doesn't work !-->
>>> </Host>
>>>
>>> Can anyone explain why the snippet above doesn't work, and if that 
>>> is the way it should be, then what is the purpose of Host/appBase?
>>>
>>> TIA
>>>
>>
>> Hi, Igal-
>>
>> What version of Tomcat are you using?  Also, it is recommended that 
>> <Context> elements not be placed directly in server.xml.  See:
>>
>> http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Defining_a_context 
>>
>>
>> That said, you shouldn't need the empty directory.  I've used an 
>> absolute path for the <Host> appBase attribute with relative paths 
>> for <Context> docBase attributes in Tomcat 6 and 7 without any 
>> problems.  I haven't tried it with absolute paths for both appBase 
>> and docBase.
>>
>> Lastly, are you sure you want "/" for the <Context> path attribute in 
>> the first example above?  The <Context> path for the default web 
>> application of a <Host> should be an empty string ("").  See:
>>
>> http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Common_Attributes 
>>
>>
>> -Terence Bandoian

Hi, Igal-

Glad you were able to get it working.  Please note the warning in the 
Tomcat docs about using the Context path attribute that reads:

"Even when statically defining a Context in server.xml, this attribute 
must not be set unless either the docBase is not located under the 
Host's appBase or both deployOnStartup and autoDeploy are false. If this 
rule is not followed, double deployment is likely to result."

This is included in:

http://tomcat.apache.org/tomcat-8.0-doc/config/context.html#Common_Attributes

For information about about how context paths relate to WAR file names 
and application directory names, see:

http://tomcat.apache.org/tomcat-8.0-doc/config/context.html#Naming

In particular, please note that "If the context path is the empty string 
them the base name will be ROOT (always in upper case)...".

The recommended practice is to create separate context XML files and 
package them in the application WAR files.  However, for simple 
installations, I've had success with something like:

       <Host name="Host"
           appBase="c:/webapps"
           autoDeploy="false"
           deployOnStartup="true"
           unpackWARs="true">

         <Context path="" docBase="ROOT" />

       </Host>

The [Tomcat]/webapps directory may then be deleted (if you don't need 
the packaged apps or doc) and ROOT.war placed directly in c:/webapps.

-Terence Bandoian


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


Mime
View raw message