Discussion:
Host appBase vs Context docBase
Igal @ getRailo.org
2014-07-05 02:04:41 UTC
Permalink
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
--
Igal Sapir
Railo Core Developer
http://getRailo.org/
Neeraj Sinha
2014-07-05 10:49:35 UTC
Permalink
Normally,we configure docBase when we want the application to be resided on
a separate directory and not inside tomcat. So, when you use docBase I
don't think you need to configure host/appbase as well.
Appbase folders go under tomcat directory parallel to default appbase
webapps. Each appbase is mapped to a particular host so we configure more
than one appbases when we want to have applications running under different
hosts deployed in the same tomcat.
Post by Igal @ getRailo.org
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.
Post by Igal @ getRailo.org
<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
<Host name="Site1" appBase="D:/www/site1" unpackWARs="false"
autoDeploy="false">
Post by Igal @ getRailo.org
<!-- 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?
Post by Igal @ getRailo.org
TIA
--
Igal Sapir
Railo Core Developer
http://getRailo.org/
---------------------------------------------------------------------
Igal @ getRailo.org
2014-07-05 18:13:22 UTC
Permalink
Normally,we configure docBase when we want the application to be resided on a separate directory and not inside tomcat
that's exactly what I'm trying to do
when you use docBase I don't think you need to configure host/appbase as well
if I don't use host/appBase then "webapps" is set as default, and then
if a document that exists in "webapps" is requested, e.g. /index.jsp and
it does not exist in my application directory, then it is served from
webapps, which is something that I really don't want to happen.

sure, I can clear the contents of the webapps folder instead of creating
the empty folder, but not sure I want to do that either.
Normally,we configure docBase when we want the application to be resided on
a separate directory and not inside tomcat. So, when you use docBase I
don't think you need to configure host/appbase as well.
Appbase folders go under tomcat directory parallel to default appbase
webapps. Each appbase is mapped to a particular host so we configure more
than one appbases when we want to have applications running under different
hosts deployed in the same tomcat.
Post by Igal @ getRailo.org
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.
Post by Igal @ getRailo.org
<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
<Host name="Site1" appBase="D:/www/site1" unpackWARs="false"
autoDeploy="false">
Post by Igal @ getRailo.org
<!-- 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?
Post by Igal @ getRailo.org
TIA
--
Igal Sapir
Railo Core Developer
http://getRailo.org/
---------------------------------------------------------------------
--
Igal Sapir
Railo Core Developer
http://getRailo.org/
Terence M. Bandoian
2014-07-05 16:48:36 UTC
Permalink
Post by Igal @ getRailo.org
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,
<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
Igal @ getRailo.org
2014-07-05 18:38:21 UTC
Permalink
Post by Terence M. Bandoian
What version of Tomcat are you using?
I've been using Tomcat 6 and 7 for a while, and now running Tomcat 8.
Post by Terence M. Bandoian
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.
Post by Terence M. Bandoian
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.
Post by Terence M. Bandoian
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
Post by Terence M. Bandoian
Post by Igal @ getRailo.org
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,
<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
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
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Common_Attributes
-Terence Bandoian
---------------------------------------------------------------------
--
Igal Sapir
Railo Core Developer
http://getRailo.org/
Terence M. Bandoian
2014-07-07 16:54:23 UTC
Permalink
Post by Igal @ getRailo.org
Post by Terence M. Bandoian
What version of Tomcat are you using?
I've been using Tomcat 6 and 7 for a while, and now running Tomcat 8.
Post by Terence M. Bandoian
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.
Post by Terence M. Bandoian
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.
Post by Terence M. Bandoian
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
Post by Terence M. Bandoian
Post by Igal @ getRailo.org
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,
<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
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
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
Igal @ getRailo.org
2014-07-07 20:21:00 UTC
Permalink
hi Terence,

thanks again for your reply.

I have autoDeploy set to false, but did not explicitly set
deployOnStartup (I think that the default is true). I am actually not
using WARs so I'm not sure how, or if, any of this is applicable to my case.


Igal
Post by Terence M. Bandoian
Post by Igal @ getRailo.org
Post by Terence M. Bandoian
What version of Tomcat are you using?
I've been using Tomcat 6 and 7 for a while, and now running Tomcat 8.
Post by Terence M. Bandoian
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.
Post by Terence M. Bandoian
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.
Post by Terence M. Bandoian
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
Post by Terence M. Bandoian
Post by Igal @ getRailo.org
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
<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
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
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
"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."
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
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
<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
---------------------------------------------------------------------
--
Igal Sapir
Railo Core Developer
http://getRailo.org/
Jeffrey Janner
2014-07-16 14:21:03 UTC
Permalink
-----Original Message-----
From: Igal @ getRailo.org [mailto:***@getrailo.org]
Sent: Friday, July 04, 2014 9:05 PM
To: Tomcat Users List
Subject: Host appBase vs Context docBase

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
--
Igal Sapir
Railo Core Developer
http://getRailo.org/
----
Igal -
For the way you want to configure your setup, your original configuration will work, except that you need to change the path from "/" to "".
That's kind of the one thing bothered me from the beginning: if you wanted a named path, like "virtdir" you have to specify it with a leading slash, "/virtdir" but for the ROOT you don't specify it. Seemed like an inconsistent treatment to me.
That said, I'd really recommend following current practices and moving the <Context> element to its own file under the conf/engine_name/host_name directory structure. For one, you don't have to worry about that path parameter ever again. The name of the XML file becomes the path value, with the exception of needing to name the file ROOT.xml to get the null path. Also, this allows you to store the file under the META-INF directory of your application and maintain the information there and have it copied to the correct place on deployment. Read the docs for more info.
Here's how to remember the difference between appbase and docbase: The appbase is the path to a directory where the applications for the host reside. Any directory or war file stored there will be deployed under the host.
The docbase is the path to the directory containing the files for a specific application. If it is a relative path, the directory is expected to reside under the appbase (take care to avoid double-deployment). If it is a fully-qualified path, then the appbase value is ignored.
It is possible to mix the two, but you need to be careful if you attempt that. Creating a new directory for each host is a good idea, even if they are empty.
If I were you, I'd really look at moving to the current configuration mechanism. After you get used to it, you'll see it makes a lot more sense. As an added plus, any change you make to the context can take effect without having to restart the entire Tomcat service.
Jeff
Loading...