-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Cris,

On 3/9/17 3:18 PM, Berneburg, Cris J. - US wrote:
>>> BTW, why doesn't getRealPath return the full path to the folder
>>> that the WAR file is in instead of null?
>> 
>> You mean for a call like getRealPath("/")?
> 
> Yes, exactly!
> 
>> Well, that would require a path to be returned to the "root" of 
>> the application. Let's say that ROOT.war is in 
>> /home/tomcat/webapps/ROOT.war and also index.html is in the 
>> "root" of the WAR File.
>> 
>> If you used getRealPath("/index.html") it would, as described, 
>> return null -- because there's no file path that could get you to
>> that file.
>> 
>> If you used getRealPath("/") and then added "/index.html" to the
>> end of it, you'd expect to be able to read index.html from the
>> resulting path (/home/tomcat/webapps/index.html). Not only does
>> that not work (because the file isn't there), it's not even the
>> right path. The "right" path (if there even is one) would be
>> something like "/home/tomcat/webapps/ROOT.war/index.html".
> 
> While that is exactly the sort of result I would want, it does
> seem kind of hackish. It isn't a response that can be supplied to a
> file system to retrieve the file. It would require some sort of
> analysis and parsing. So I can see why null is the safer answer,
> even if I don't like it. ;-)

If you really REALLY want a file path, you could use the catalina.base
system property or the tmpdir and go from there. The former is
Tomcat-specific, of course, and the tmpdir would be *anywhere*, but if
you just really REALLY need a path on the disk, you could get it from
there.

>> So when the WAR is not unpacked, there really isn't any 
>> meaningful return value from getRealPath, even for special- cases
>> like "" or "/".
> 
> Thanks for explaining.  I need to absorb all that info.
> 
> Also, maybe I'm not asking the right question. How do you all 
> configure the location of a special folder that is not part of the 
> deployment package itself? A site-specific config file perhaps?

Well-known location like /etc/myapp/config.cfg? Well-known
configuration URL like https://internal-config.myapp.com/config.cfg?

> Currently I'm using getRealPath for a relative-path location, but
> it sounds like that may need to be changed. Fortunately, the impact
> points are somewhat limited since all calls to getRealPath are
> wrapped with other centralized methods.

If the file can be bundled with the WAR file (which would be best),
then you should get
ServletContext.getResource("/path/rooted/in/the/WAR/file/config.cfg").

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJYwcrTAAoJEBzwKT+lPKRYYl4QAK8P3tdjGOgYZ/6MK4cj+vHb
fakVPT6IKu99ACdhubH0rllxQOSnaXzi/OGxtp3QxU0HHogb/zPYeW/eky5Hmq0I
G9aJnTMXcvvlpPBwB/8FymKcIExW+NtRlrzeSKxyOQY2sPHvnyaEcqQSi5Gj0fvq
7EYQ8C2D+U/n/heU0byntAAq+/vdyvTGLuH7vabjDa0BkkK8i4RDLjUWHbQhTg45
sIbmG75pexUN654uBJ9Y2cyfVC9ZI/pyhqRv4/vHq5W5OBOWI87mRmOfd5KpxQJF
z8ryXW0yImyqHc5TSmFTf4uW2A+4x4r/s9V2ghQqZMmPDYIRvjcHOzmBtTk38FGm
oMQhkfY46XAat480aTc35KmWMutzyMdlYERcCf0Xet+YlGQKAyjkj5xXt1X+YjnH
WQmPynjJizVzrWo6spwWNrVs5uMK3+fF2y4ubRjJ8KCeSBEWK21Y0Zu8ueyeURGc
KG7qfHM53uooD7+CQnfdkBFjICWJHXPGfqHEv5eHbPlGNzUQJGNg6eVLT0QjmHev
cJ1JALl1K9D5O1a3tkdjDR4mgXRfXY3qWnqQOeTfEfzjcyBnIJ+0Z7KRxYNx5XOQ
j+yBI7xdOndNglEtVCGj8gJARKxfhDHpvbQMhY4f4O3pUg//P6ckzGP2QgbInD8J
f63TvM/Zas0u6BmmN0Do
=AUo9
-----END PGP SIGNATURE-----

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

Reply via email to