You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ward <wa...@gmail.com> on 2009/03/26 18:07:44 UTC

Deployment: do not delete specified folder

Hi all,

I'm working on a web application in which users are able to upload
files to server. The files are stored outside the tomcat webapps
directory, but to be able to acces them via the web-application, I
created a symbolic link into my application's root directory, which
points to the folder where the files are actually stored.

The problem is, that everytime I upload my new .war file (which is
then deployed), de undeploy/deploy-process removes all the original
files/folders of the application, including the symbolic link, AND the
files in the actual file-folder (so not only the symbolic link is
removed, it is treaten as a real folder, which is deleted then)

As this is unwanted behaviour, I'm looking for a way to 'tell' the
deployment-process not to delete the symbolic link, or to safely
delete it (just the link, not the folder), and create it again after
the deployment has finished.

I've been looking for a solution, but didn't found one. I think this
problem might be solved with an appropriate ant-task, but I can't
figure out which, en where to place it.

I'm using Tomcat server version 6.0.18
Operating system is Suse Linux Enterprise v 10

Thanks in advance for helping me out!

Grtz

Ward

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


RE: Deployment: do not delete specified folder

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ward [mailto:wardlootens@gmail.com]
> Subject: Re: Deployment: do not delete specified folder
> 
> should have asked this a lot earlier, would have
> saved me a lot of frustrations!

What you want to do is not uncommon; it would be a useful enhancement for DefaultServlet to be able to configure external directories based on URL paths.

 - 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: Deployment: do not delete specified folder

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Caldarale, Charles R
> Subject: RE: Deployment: do not delete specified folder
> 
> What you want to do is not uncommon; it would be a useful enhancement
> for DefaultServlet to be able to configure external directories based
> on URL paths.

There is another way to do this, which I should have thought of earlier - and it doesn't involve any coding, just configuration.  If you keep your static resources outside of Tomcat's directory structure, you can just declare a <Context> element that defines the location and let the existing DefaultServlet handle them.

For example, if your images are in /usr/media, and you want the URL http://server/MyApp/media to reference them, create the file conf/Catalina/localhost/MyApp#media.xml containing the following:
<Context docBase="/usr/media"/>

That will create an additional trivial webapp whose only servlet is DefaultServlet, and you won't have to bother with symlinks or any coding of your own.

 - 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: Deployment: do not delete specified folder

Posted by Ward <wa...@gmail.com>.
okey

Thanks a lot mate, should have asked this a lot earlier, would have
saved me a lot of frustrations!

Ward

2009/3/27 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Ward [mailto:wardlootens@gmail.com]
>> Subject: Re: Deployment: do not delete specified folder
>>
>> Read the desired file, and then write it to the outputstream of the
>> response?
>
> Exactly.  That's all the DefaultServlet does.  (Ok, not quite all, but that's the gist of it.)
>
>  - 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
>
>

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


RE: Deployment: do not delete specified folder

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ward [mailto:wardlootens@gmail.com]
> Subject: Re: Deployment: do not delete specified folder
> 
> Read the desired file, and then write it to the outputstream of the
> response?

Exactly.  That's all the DefaultServlet does.  (Ok, not quite all, but that's the gist of it.)

 - 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: Deployment: do not delete specified folder

Posted by Ward <wa...@gmail.com>.
2009/3/26 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Ward [mailto:wardlootens@gmail.com]
>> Subject: Re: Deployment: do not delete specified folder
>>
>> Can you please tell/hint me how do I access file on
>> server, not in webserver directory
>
> Static resources are normally handled by Tomcat's built-in DefaultServlet, which does map URL paths to file system paths.  There's nothing stopping you from using your own servlet (likely just extending DefaultServlet) to handle requests for /somedir/somefile and retrieving the file from some alternate location.
Okey, I think I get you point here, but I'm just somewhat stuck on the
'retrieving the file from some alternate location'...
How exactly do I have to handle this?
Read the desired file, and then write it to the outputstream of the response?

Ward

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


RE: Deployment: do not delete specified folder

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ward [mailto:wardlootens@gmail.com]
> Subject: Re: Deployment: do not delete specified folder
> 
> Can you please tell/hint me how do I access file on
> server, not in webserver directory

Static resources are normally handled by Tomcat's built-in DefaultServlet, which does map URL paths to file system paths.  There's nothing stopping you from using your own servlet (likely just extending DefaultServlet) to handle requests for /somedir/somefile and retrieving the file from some alternate location.

 - 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: Deployment: do not delete specified folder

Posted by Ward <wa...@gmail.com>.
2009/3/26 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Ward [mailto:wardlootens@gmail.com]
>> Subject: Re: Deployment: do not delete specified folder
>>
>> So supposed there is a file in the /media directory, let's
>> say file.jpg There is no way to acces this file trough an
>> url without creating a link to the media folder
>
> You're confusing URLs with file system paths.  Whatever servlet is fielding requests for /media can choose to serve the resource from wherever it wants.
>
>  - Chuck

Sorry, I don't see how to do that
Can you please tell/hint me how do I access file on server, not in
webserver directory, via URL (http://server/MyApp/somedir/somefile
(cause that's basically the thing I wanna do)
I managed to do with symbolic link, but if you say there are other,
more easy solutions, I'm willing to adopt them... unfortunately I
can't figure them out myself...

Thanks

Ward

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


RE: Deployment: do not delete specified folder

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ward [mailto:wardlootens@gmail.com]
> Subject: Re: Deployment: do not delete specified folder
> 
> So supposed there is a file in the /media directory, let's 
> say file.jpg There is no way to acces this file trough an 
> url without creating a link to the media folder

You're confusing URLs with file system paths.  Whatever servlet is fielding requests for /media can choose to serve the resource from wherever it wants.

 - 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: Deployment: do not delete specified folder

Posted by Ward <wa...@gmail.com>.
Okey,

I might have been not specific enough with my question:
wath I wanna do is to be able to link to the files (eg to download, or 
to use an image in a html-page)

So supposed there is a file in the /media directory, let's say file.jpg
There is no way to acces this file trough an url without creating a link 
to the media folder (At least, this is what I found out, or am I wrong 
here??)

So what I do is to create a symbolic link, in the MyApp-directory, 
(media -> /media/) and than I can use
http://server/MyApp/media/file.jpg to acces the file.jpg

Indeed, like you say, I can acces the target directory directly in my 
Java code, that's no problem, but what I wanna do is something different?

Greetings

Ward

Caldarale, Charles R schreef:
>> From: Ward [mailto:wardlootens@gmail.com]
>> Subject: Deployment: do not delete specified folder
>>
>> to be able to acces them via the web-application,
>> I created a symbolic link into my application's 
>> root directory, which points to the folder where
>> the files are actually stored.
> 
> "Doctor, doctor, it hurts when I do this."
> 
> Why not just access the target directory directly, and eliminate your self-imposed complexity with all of its undesirable side effects?  If you don't want to hard-code the path, set it in an environment variable, system property, or initialization parameter for the webapp.  Look here for the last item:
> 
> http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Context%20Parameters
> 
>  - 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
> 
> 

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


RE: Deployment: do not delete specified folder

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ward [mailto:wardlootens@gmail.com]
> Subject: Deployment: do not delete specified folder
> 
> to be able to acces them via the web-application,
> I created a symbolic link into my application's 
> root directory, which points to the folder where
> the files are actually stored.

"Doctor, doctor, it hurts when I do this."

Why not just access the target directory directly, and eliminate your self-imposed complexity with all of its undesirable side effects?  If you don't want to hard-code the path, set it in an environment variable, system property, or initialization parameter for the webapp.  Look here for the last item:

http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Context%20Parameters

 - 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