> -----Original Message----- > From: Mark Eggers [mailto:its_toas...@yahoo.com] > Sent: Monday, December 16, 2013 4:19 PM > To: Tomcat Users List > Subject: Re: linking (limiting???) > > Replies inline. > > Note, people on this mailing list frown on top-posting (see items 6 and > 7 here: http://tomcat.apache.org/lists.html). It does make the reply > and response difficult to follow without rereading the entire thread. > > Please either reply inline or at the end, so people late to the party > (or those of us with short / fragmented memory :-p) can remember what's > going on. > > On 12/16/2013 1:00 PM, Ray Holme wrote: > > I have been trying three scenarios. So far one works (least security > and not good for all OS versions). > > Again thanks to both Marks for the pointers, but I am afraid they are > not working yet. > > > > My goal is to enable one directory to be used which is outside the > application (and tomcat too) > > .../webapps/mywebapp hierarchy > > which mywebapp.war will replace with a new release > > > > use 1: to store/retrieve images locally to a machine > > under application control (db stores names of files) > > use 2: to store a static movie - demo (no update - this is the > > simple test case I try) > > > > The goal is to get this stuff out of the war file (leaving nothing, > an > > empty dir, or a link as needed - see below). All of the below > require > > apache/tomcat to be down when you make the changes, then restart to > > test > > > > a) IF you have linux (or unix) or osx - you can do symbolic linking > > simply move the directory and link (my case below): > > cd ..../webapps/mywebapp; mv images /opt; ln -s /opt/images > > > > and to enable symbolic linking to other directories on your > machine > > (all of them) > > > > create a ..../webapps/mywebapp/META-INF/context.xml file (or edit > > the one you have) > > > > <?xml version="1.0" encoding="UTF-8"?> <Context allowLinking="true"> > > </Context> > > > > advantages for this method: works simply > > faults: MS os's don't do symbolic; also opens up ALL linking > (security issues? probably) > > > > BUT THERE ARE 2 other SAFER more restrictive ways below, both also > done in > > the same context.xml file (if I can get either of them to work - > > the examples often say the server.xml file, but there is only one of > > them in the top tomcat conf directory, which has NO context > references > > - but if they go there, then path= probably needs to be specified.) > > > > b) > > > > <?xml version="1.0" encoding="UTF-8"?> <Context > > aliases="/images=/opt/images" /> </Context> > > > > c) > > > > <?xml version="1.0" encoding="UTF-8"?> > > <Context <Resources > className="org.apache.naming.resources.VirtualDirContext" > > extraResourcePaths="/images=/opt/images" /> > > </Context> > > > > I hope that you meant: > > <Context> > <Resources className="org.apache.naming.resources.VirtualDirContext" > extraResourcePaths="/images=/opt/images" /> > </Context> > > > > ------------------------- > > These are both more security conscious and might should work for MS > > (with MS correct paths such as d:\images) > > > > Which of these is simpler and/or better - I have no idea. Net > comparisons don't say. > > but the VirtualDirContext.html pages say: DO NOT USE FOR > PRODUCTION > > of course- they don't say why NOT > > I'm not sure that this is valid any more. > > > Why both require the escaped greater than sign, beats me too. "/>" > > It's not an escaped greater than sign. It's how one closes an empty tag > in XML. You could also have written it the following way: > > <Context> > <Resources className="org.apache.naming.resources.VirtualDirContext" > extraResourcePaths="/images=/opt/images"> > </Resources> > </Context> > > > I would have thought it would be simply ">" on the 2nd and 3rd > > lines resp. (b and c) > > > > NEITHER OF THESE WORKED FOR ME! (so far and I have tried many > > variants) > > > > Do I have to have the symbolic link (in Linux - I did for a) > obviously) > > or should this be a plain empty directories (like Linux/Unix > mount points) > > or should there be no "../webapps/myapp/images" anything at > all? > > There should be nothing in your web application at all. However, > according to the documentation, the alias path (and by extension, the > VirtualDirContext) are searched first, so it shouldn't matter as long > as the target directory exists. > > > > > In the manual version there are more parameters, but most folks say > to > > drop > > > > "path=mywebapp" > > > > and the rest seem to not be relevant to what I am doing so I cut them > out. Maybe that is the problem. > > > > Here is the example I found under VirtualDirContext online > > > > <Context path="/mywebapp" > > docBase="/Users/theuser/mywebapp/src/main/webapp" > <Resources > className="org.apache.naming.resources.VirtualDirContext" > > > extraResourcePaths="/pictures=/Users/theuser/mypictures,/movies=/Users > > /theuser/mymovies" /> <Loader > > className="org.apache.catalina.loader.VirtualWebappLoader" > > virtualClasspath="/Users/theuser/mywebapp/target/classes" /> > > <JarScanner scanAllDirectories="true" /> </Context> > > The example you quoted was for the directory structure listed above the > example. > > Do not use path if you're deploying in the appBase directory defined in > server.xml ($CATALINA_BASE/webapps by default), which you are. >
Actually, the path is taken from the name of the context.xml file and is therefore ignored if specified here. It has nothing to do with deploying in the appBase directory or not. > Do not use docBase at all - this is for locating an application outside > of the appBase directory defined in server.xml. > > Now using the following context.xml: > > <Context> > <Resources className="org.apache.naming.resources.VirtualDirContext" > extraResourcePaths="/images=/opt/images" /> > </Context> > > Your application should end up with <img> tags looking like the > following: > > <img src="images/picture1.png" alt="Picture 1"> > > Things are a bit nicer if you use the core tag libraries, and of course > if you're using HTML 5 you'll need to close the tag (the above is HTML > 4.01 Transitional). > > I wrote a quick web application to access some pictures in my home > directory with: > > <?xml version="1.0" encoding="UTF-8"?> > <Context> > <Resources > className="org.apache.naming.resources.VirtualDirContext" > > extraResourcePaths="/pictures=/home/mdeggers/Pictures"/> > </Context> > > This was done on Fedora 19, Tomcat 7.0.42, JRE 1.7.0_45, and it worked > as advertised. > > I also tried the following, which worked: > > <?xml version="1.0" encoding="UTF-8"?> > <Context aliases="/pictures=/home/mdeggers/Pictures"> > </Context> > > Links in my index.jsp: > > <img src="pictures/snapshot1.png" alt="snapshot 1"><br> <img > src="pictures/snapshot2.png" alt="snapshot 2"><br> <img > src="pictures/snapshot3.png" alt="snapshot 3"><br> <img > src="pictures/snapshot4.png" alt="snapshot 4"><br> > > I normally use the core tag library, so those links would be: > > <img > src='<c:url value="/pictures/snapshot1.png"/>' alt="snapshot 1"><br> > <img > src='<c:url value="/pictures/snapshot2.png"/>' alt="snapshot 2"><br> > <img > src='<c:url value="/pictures/snapshot3.png"/>' alt="snapshot 3"><br> > <img > src='<c:url value="/pictures/snapshot4.png"/>' alt="snapshot 4"><br> > > . . . . just my two cents. > /mde/ > While both definitions above are functionally equivalent if used in the top-level index.jsp, it's best to use the path string specified in the second example in both cases. The first is a relative path and will fail if used in a file further down in the webapps directory structure (assuming on a single, top-level "pictures" directory). --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org