Re: Download link to jar in WEB-INF

Discussion in 'Java' started by Sudsy, Apr 1, 2004.

  1. Sudsy

    Sudsy Guest

    Wendy S wrote:
    <snip>
    > But it would be easier to just put two copies of the .jar file on the
    > server. ;) Somewhere you must create this .jar file, just make it part of
    > that process to copy it to both places. (Ant task?)


    Perfect application for a symbolic link...
    Sudsy, Apr 1, 2004
    #1
    1. Advertising

  2. /Sudsy/:
    > Wendy S wrote:
    > <snip>
    >
    >> But it would be easier to just put two copies of the .jar file on the
    >> server. ;) Somewhere you must create this .jar file, just make it
    >> part of
    >> that process to copy it to both places. (Ant task?)

    >
    > Perfect application for a symbolic link...


    On Windows with NTFS one may use:

    fsutil hardlink create /NewFilename/ /ExistingFilename/

    for files (this is available on XP, don't know for NT4/2000). For
    directories, there's a free "junction" utility:

    http://www.sysinternals.com/ntw2k/source/misc.shtml#junction

    --
    Stanimir
    Stanimir Stamenkov, Apr 1, 2004
    #2
    1. Advertising

  3. Sudsy

    Wendy S Guest

    "Sudsy" <> wrote in message
    news:...
    > Wendy S wrote:
    > <snip>
    > > But it would be easier to just put two copies of the .jar file on the
    > > server. ;) Somewhere you must create this .jar file, just make it part

    of
    > > that process to copy it to both places. (Ant task?)

    >
    > Perfect application for a symbolic link...


    Soft links in WEB-INF/lib reportedly have problems:
    http://www.mail-archive.com//msg99664.html

    So that means placing the actual file in WEB-INF/lib and the link in a
    visible directory, which I am not convinced complies with the
    specification's requirement that nothing under WEB-INF be served.

    I'm curious whether anyone has tried this?

    I vote for having a self-contained, cross-platform .war file over saving a
    bit of disk space and complicating deployment.

    --
    Wendy in Chandler, AZ
    Wendy S, Apr 1, 2004
    #3
  4. Sudsy

    Sudsy Guest

    Wendy S wrote:
    <snip>
    > Soft links in WEB-INF/lib reportedly have problems:
    > http://www.mail-archive.com//msg99664.html
    >
    > So that means placing the actual file in WEB-INF/lib and the link in a
    > visible directory, which I am not convinced complies with the
    > specification's requirement that nothing under WEB-INF be served.
    >
    > I'm curious whether anyone has tried this?
    >
    > I vote for having a self-contained, cross-platform .war file over saving a
    > bit of disk space and complicating deployment.
    >


    The links mentioned in the article cited were going in the other
    direction. I just ran a test like so:
    $ cd $WEBAPP
    $ ln -s WEB-INF/<path_to_file> <file_name>
    I then retrieved <file_name> from a browser without difficulty.
    Of course this was the behaviour I expected, which is why I made
    the suggestion in the first place.
    I'm running Linux but another poster stated that links are also
    supported under Windoze XP.
    Sudsy, Apr 1, 2004
    #4
  5. /Sudsy/:

    > The links mentioned in the article cited were going in the other
    > direction. I just ran a test like so:
    > $ cd $WEBAPP
    > $ ln -s WEB-INF/<path_to_file> <file_name>
    > I then retrieved <file_name> from a browser without difficulty.
    > Of course this was the behaviour I expected, which is why I made
    > the suggestion in the first place.


    The point is one have no guarantees the web application is
    "expanded" - the servlet container is not obliged to extract the WAR
    file in order to use it. How do you define a soft link in a
    WAR(JAR/ZIP) archive?

    The ServletContext#getResource(String) method retrieves a specified
    resource and you don't have to know if the resource is on a file
    system or somewhere else.

    I think the best approach is to have configured (with a resource
    path parameter) servlet instances to retrieve such "special"
    resources (using the above mentioned method) where the servlets are
    mapped to the desired URLs.

    --
    Stanimir
    Stanimir Stamenkov, Apr 1, 2004
    #5
  6. On Thu, 01 Apr 2004 00:16:35 -0500, Sudsy wrote:

    > Perfect application for a symbolic link...


    Thanks Sudsy, I'll check that out.
    Andrew Thompson, Apr 2, 2004
    #6
  7. On Thu, 01 Apr 2004 21:55:29 +0300, Stanimir Stamenkov wrote:

    > /Sudsy/:
    >
    >> The links mentioned in the article cited were going in the other
    >> direction. I just ran a test like so:
    >> $ cd $WEBAPP
    >> $ ln -s WEB-INF/<path_to_file> <file_name>
    >> I then retrieved <file_name> from a browser without difficulty.
    >> Of course this was the behaviour I expected, which is why I made
    >> the suggestion in the first place.

    >
    > The point is one have no guarantees the web application is
    > "expanded" - the servlet container is not obliged to extract the WAR
    > file in order to use it.


    Ummm.. Perhaps that may be the case, but
    My files are in WEB-INF, but they are
    _not_ a .WAR file, each file is there on
    the filesystem (inside the ..lib directory
    so I can access the classes in JSP's).

    The JAR file is obviously an archive (in itself),
    but I want to serve it up to visitors as is -
    no subtleties of individual classes or bits of it.
    It is under 20Kb and they need the entire thing, here..
    <http://www.physci.org/jvmclean.jsp?pt=main#download>

    b) My site is operating from a Linux based server..
    <http://uptime.netcraft.com/up/graph/?host=www.physci.org>
    (shrugs) ..for the record.

    I do not quite understand how this symbolic
    link works, so I'll use Sudsy's example above,
    do a bit of googling and see if I can figure
    it out..

    Thanks all.

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
    Andrew Thompson, Apr 2, 2004
    #7
  8. /Andrew Thompson/:

    > Ummm.. Perhaps that may be the case, but
    > My files are in WEB-INF, but they are
    > _not_ a .WAR file,


    I've meant the JAR you want to serve is in the application WAR, and
    one can't define symbolic link in the WAR file: it is on OS/file
    system dependent feature.

    > each file is there on
    > the filesystem (inside the ..lib directory


    The servlet spec doesn't say anything about deploying unpackaged
    applications. In your case you could make into account the fact your
    servlet container makes use of an "expanded" application archive and
    use the symbolic links which where already described.

    But you may write simple servlet, too:

    protected void doGet(HttpServletRequest pRequest,
    HttpServletResponse pResponse)
    throws ServletException, IOException
    {
    ServletContext svtCtx = getServletContext();
    String pathInfo = pRequest.getPathInfo();
    URL resURL = svtCtx.getResource("/WEB-INF" + pathInfo);
    URLConnection resConn = resURL.openConnection();
    pResponse.setContentType(resConn.getContentType());
    pResponse.setContentLength(resConn.getContentLength());
    pResponse.setDateHeader("Last-Modified",
    resConn.getLastModified());
    InputStream ins = resConn.getInputStream();
    OutputStream outs = pResponse.getOutputStream();
    byte[] buf = new byte[4096];
    int readCount;
    while ((readCount = ins.read(buf)) != -1) {
    outs.write(buf, 0, readCount);
    }
    ins.close();
    }

    Map it to a desired path (e.g. "/whatever/*", but again:
    "/WEB-INF/*", even "/web-inf/*" won't work). Then you will be able
    to fetch any file residing in you application WEB-INF/ directory. If
    we map the servlet to "/whatever/*", a request for
    "/whatever/web.xml" would fetch "/WEB-INF/web.xml". The servlet
    could be modified to suit more specialized need, but I hope you got
    my point.

    > so I can access the classes in JSP's).


    I'm not sure I've crearly understood this one, but anyway.

    --
    Stanimir
    Stanimir Stamenkov, Apr 2, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Thompson

    Re: Download link to jar in WEB-INF

    Andrew Thompson, Mar 31, 2004, in forum: Java
    Replies:
    0
    Views:
    379
    Andrew Thompson
    Mar 31, 2004
  2. Matthew Macchia
    Replies:
    3
    Views:
    1,050
    Roedy Green
    Apr 13, 2004
  3. Hans
    Replies:
    3
    Views:
    2,450
    Ryan Stewart
    May 16, 2004
  4. Newcomer

    jar files in WEB-INF/lib

    Newcomer, Jul 6, 2004, in forum: Java
    Replies:
    2
    Views:
    447
    Roedy Green
    Jul 6, 2004
  5. Arnold Peters
    Replies:
    0
    Views:
    551
    Arnold Peters
    Jan 5, 2005
Loading...

Share This Page