You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Miguel Almeida <mi...@gmail.com> on 2012/08/06 21:26:15 UTC
[Tomcat 7] Why can't you use automatic deployment and exploded WAR
when docBase is outside appBase?
Dear all,
I am going to divide my question in 2. The first part concerns a change in
Tomcat7's behaviour (vs Tomcat6) that I would like to understand. The 2nd
question is what lead me to the question, and it's a practical Java issue -
where help is also appreciated.
Onwards to the questions.
Consider the following context file jamesbond.xml in
$CATALINA_BASE/conf/[engine_name]/[host_name]):
<Context docBase="/srv/apps/jamesbond.war" unpackWAR="true"
debug="0" privileged="true">
<Environment name="my.env" value="VAL" type="java.lang.String"
override="true"/>
</Context>
*1)* In Tomcat 6 you'd update the war at /srv/apps and it would
automatically be redeployed and exploded.
However, in Tomcat 7 this isn't happening.
>From the docs (http://tomcat.apache.org/tomcat-7.0-doc/config/host.html), a
new important text that wasn't in 6 reads:
unpackWARs - (...) WAR files located outside of the Host's *appBase* will
not be expanded.
And in
http://tomcat.apache.org/tomcat-7.0-doc/config/host.html#Automatic%20Application%20Deployment:
- When using automatic deployment, the docBase defined by an XML
Context<http://tomcat.apache.org/tomcat-7.0-doc/config/context.html>file
should be outside of the
appBase directory. If this is not the case, difficulties may be experienced
deploying the web application or the application may be deployed twice. The
deployIgnore attribute can be used to avoid this situation.
Both these rules means you can't have automatic deployment of files outside
appBase and explode them (into appBase).
Why is this? How can one have the same behaviour as in Tomcat 6: have the
war* outisde appBase*, use a context xml like the one above and have the
application exploded.
*2) *The motivation for this is a simple code
ServletContext.getRealPath("/") to create a simple temporary inputstream
that works in Tomcat6 but doesn't in Tomcat7 (because getRealPath("/") will
return null). Setting up a dedicated directory seems a bit of a hassle for
a temporary inputstream.
Cheers,
Miguel Almeida
Re: [Tomcat 7] Why can't you use automatic deployment and exploded
WAR when docBase is outside appBase?
Posted by Mark Eggers <it...@yahoo.com>.
On 8/6/2012 1:43 PM, Miguel Almeida wrote:
> Thanks for the input regarding 2). What's the difference between using
> javax.servlet.context.tempdir vs java.io.tmpdir ?
>
> Also, do you know the answer to 1 - ie, why did the change occur regarding
> not exploding when the WAR is outside appBase?
>
>
Please don't top post. I just switched to using a real mail client and I
now know why others lament so much about this.
Anyway, from the fine documentation at:
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
workDir
Pathname to a scratch directory to be provided by this Context for
temporary read-write use by servlets within the associated web
application. This directory will be made visible to servlets in the web
application by a servlet context attribute (of type java.io.File) named
javax.servlet.context.tempdir as described in the Servlet Specification.
If not specified, a suitable directory underneath $CATALINA_BASE/work
will be provided.
So in short, read the Servlet Specification. (This is also of type File,
while the property is of type String.)
I suspect that if you use javax.servlet.context.tempdir, the scratch
space will be under CATALINA_BASE/work/[Engine]/[host]/[app].
[Engine] is by default Catalina
[host] is by default localhost
[app] is your web application context name
This is different than java.io.tmpdir, which is set to CATALINA_BASE/temp.
One of the nice things about using javax.servlet.context.tempdir is that
it's deleted when you undeploy your application.
Another nice thing about javax.servlet.context.tempdir is that you get a
location per web application, not a location per Tomcat. This means that
various contexts can't step on each other.
One of the not so nice things about javax.servlet.context.tempdir is
that it normally doesn't exist outside of a servlet container or web
application server. This means that if you do unit testing, you'll have
to define that property when you run tests with
-Djavax.servlet.context.tempdir="somewhere-i-can-write" and open this as
a file (see above for comments about type).
For your answer to question 1, I guess you'll have to read any
discussion on the development mailing list. Searchable archives are
available online. I'm just a user, and while I casually read the
development list I don't currently don't participate.
. . . just my 2 cents.
/mde/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: [Tomcat 7] Why can't you use automatic deployment and exploded
WAR when docBase is outside appBase?
Posted by Miguel Almeida <mi...@gmail.com>.
Thanks for the input regarding 2). What's the difference between using
javax.servlet.context.tempdir vs java.io.tmpdir ?
Also, do you know the answer to 1 - ie, why did the change occur regarding
not exploding when the WAR is outside appBase?
On Mon, Aug 6, 2012 at 9:32 PM, Mark Eggers <it...@yahoo.com> wrote:
> On 8/6/2012 12:40 PM, Caldarale, Charles R wrote:
>
>> From: Miguel Almeida [mailto:migueldealmeida@gmail.**com<mi...@gmail.com>
>>> ]
>>> Subject: [Tomcat 7] Why can't you use automatic deployment
>>> and exploded WAR when docBase is outside appBase?
>>>
>>
>> The motivation for this is a simple code ServletContext.getRealPath("/"*
>>> *)
>>> to create a simple temporary inputstream that works in Tomcat6 but
>>> doesn't
>>> in Tomcat7 (because getRealPath("/") will return null).
>>>
>>
>> And, if you check the servlet spec, getRealPath() is *never* guaranteed
>> to work. Your code should be using either getResourceAsStream() or looking
>> at the javax.servlet.context.tempdir context attribute to find where it can
>> create temporary files.
>>
>> - Chuck
>>
>
> +1
>
> I just spent the better part of a week ferreting out exactly this mess.
> The original application would read from and write to files inside the web
> application. Even worse, the original application hard-coded the path in a
> set of variables set at web application load time.
>
> This meant that every time the server was changed, the application moved,
> or the application name changed, the war file had to be unpacked, these
> values changed, and then the war file had to be repacked.
>
> Use getResourceAsStream() for things you need to read. Put those items in
> WEB-INF/classes or in a jar in WEB-INF/lib. If you need to write temporary
> files, use java.io.tmpdir, file.separator, and possibly createTempFile().
>
> Tomcat (catalina.sh) sets java.io.tmpdir to $CATALINA_BASE/temp for your
> convenience by default.
>
> . . . just my (somewhat frustrated) 2 cents.
> /mde/
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.**apache.org<us...@tomcat.apache.org>
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
Re: [Tomcat 7] Why can't you use automatic deployment and exploded
WAR when docBase is outside appBase?
Posted by Mark Eggers <it...@yahoo.com>.
On 8/6/2012 12:40 PM, Caldarale, Charles R wrote:
>> From: Miguel Almeida [mailto:migueldealmeida@gmail.com]
>> Subject: [Tomcat 7] Why can't you use automatic deployment
>> and exploded WAR when docBase is outside appBase?
>
>> The motivation for this is a simple code ServletContext.getRealPath("/")
>> to create a simple temporary inputstream that works in Tomcat6 but doesn't
>> in Tomcat7 (because getRealPath("/") will return null).
>
> And, if you check the servlet spec, getRealPath() is *never* guaranteed to work. Your code should be using either getResourceAsStream() or looking at the javax.servlet.context.tempdir context attribute to find where it can create temporary files.
>
> - Chuck
+1
I just spent the better part of a week ferreting out exactly this mess.
The original application would read from and write to files inside the
web application. Even worse, the original application hard-coded the
path in a set of variables set at web application load time.
This meant that every time the server was changed, the application
moved, or the application name changed, the war file had to be unpacked,
these values changed, and then the war file had to be repacked.
Use getResourceAsStream() for things you need to read. Put those items
in WEB-INF/classes or in a jar in WEB-INF/lib. If you need to write
temporary files, use java.io.tmpdir, file.separator, and possibly
createTempFile().
Tomcat (catalina.sh) sets java.io.tmpdir to $CATALINA_BASE/temp for your
convenience by default.
. . . just my (somewhat frustrated) 2 cents.
/mde/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: [Tomcat 7] Why can't you use automatic deployment and exploded
WAR when docBase is outside appBase?
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Miguel Almeida [mailto:migueldealmeida@gmail.com]
> Subject: [Tomcat 7] Why can't you use automatic deployment
> and exploded WAR when docBase is outside appBase?
> The motivation for this is a simple code ServletContext.getRealPath("/")
> to create a simple temporary inputstream that works in Tomcat6 but doesn't
> in Tomcat7 (because getRealPath("/") will return null).
And, if you check the servlet spec, getRealPath() is *never* guaranteed to work. Your code should be using either getResourceAsStream() or looking at the javax.servlet.context.tempdir context attribute to find where it can create temporary files.
- 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 unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: [Tomcat 7] Why can't you use automatic deployment and exploded
WAR when docBase is outside appBase?
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Miguel,
On 8/6/12 3:26 PM, Miguel Almeida wrote:
> Consider the following context file jamesbond.xml in
> $CATALINA_BASE/conf/[engine_name]/[host_name]):
>
> <Context docBase="/srv/apps/jamesbond.war" unpackWAR="true"
> debug="0" privileged="true"> <Environment name="my.env" value="VAL"
> type="java.lang.String" override="true"/> </Context>
>
> *1)* In Tomcat 6 you'd update the war at /srv/apps and it would
> automatically be redeployed and exploded.
>
> However, in Tomcat 7 this isn't happening.
>> From the docs
>> (http://tomcat.apache.org/tomcat-7.0-doc/config/host.html), a
> new important text that wasn't in 6 reads: unpackWARs - (...) WAR
> files located outside of the Host's *appBase* will not be
> expanded.
>
> And in
> http://tomcat.apache.org/tomcat-7.0-doc/config/host.html#Automatic%20Application%20Deployment:
>
>
- - When using automatic deployment, the docBase defined by an XML
> Context<http://tomcat.apache.org/tomcat-7.0-doc/config/context.html>file
>
>
should be outside of the
> appBase directory. If this is not the case, difficulties may be
> experienced deploying the web application or the application may be
> deployed twice. The deployIgnore attribute can be used to avoid
> this situation.
>
> Both these rules means you can't have automatic deployment of files
> outside appBase and explode them (into appBase).
Do you mean "automatic deployment" or "automatic redeployment"? If you
want to update a WAR file that is outside of the appBase, then update
the WAR file and then 'touch' the XML file in
$CATALINA_BASE/conf/[engine_name]/[host_name]/jamesbond.xml.
> Why is this? How can one have the same behaviour as in Tomcat 6:
> have the war* outisde appBase*, use a context xml like the one
> above and have the application exploded.
Do you really care about the WAR file being exploded? If this is
really a complaint about your question #2 (handled by others
separately within this thread), then you should be using the temp dirs
instead of getRealPath and you won't have to worry about the lack of
WAR-explosion anymore.
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAlAhRK0ACgkQ9CaO5/Lv0PBElgCff5o8N1rNnTKAZ1HHRKxBqKTU
t+oAmwWEcvU1uDLWX6zkYNT+QnhLSqxk
=Z6qA
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org