-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Cris,
On 3/7/17 10:27 AM, Berneburg, Cris J. - US wrote:
> [SNIP]
>
>>> chris S>>> getRealPath is a bad idea. <<<
>>>
>>> For my education's sake, would you please explain that?
>>> [SNIP]
>>
>> There is no guarantee it will return a non-null value. The
>> typical reason is if the app is running from a packed WAR. Using
>> it reduces the portability of your application.
>>
>> Mark
>
> Thanks for explaining that. Never occurred to me that running from
> a WAR would return null.
>
> I used getRealPath thinking it would *increase* portability, since
> yet-another-config-option would not need to be manually set (or
> verified) after every deployment or in a different environment.
> "Why did the such-and-so fail? Oh... I forgot to set the folder
> location - again." By using getRealPath the setting never, ever
> needs to be configured - it's automatic.
>
> But now I may need to rethink that.
>
> 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("/")?
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".
So when the WAR is not unpacked, there really isn't any meaningful
return value from getRealPath, even for special-cases like "" or "/".
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBCAAGBQJYvupLAAoJEBzwKT+lPKRYinQQALRk87wqtMBXKsPf3XCm7F4L
l72cqnMgqpWzSJ4fFP/yZq/TyNAH9Oewyk0i/HZNMvqJZw5539sdpyirpDLilEe3
VMW6pzWI3FRLVkUI1CtCsqrP0onm77Avlp+U0P1xjr8lF+FhgN7FWX6WifDvlV4b
ugorEoH1LXnyTfadRIe7q57APnwEz5cdepCKJv5bPT5bl8UCTEv3jnodbDkKzzXY
lK3ZcBSz9qXQ+F7gIedR94RmlM63jzryzlFWJXhXOIFdWCncFrSNXlJrEnu07VMH
PNsZ5Pt189jzq7u4YcUaDiSgGDRnGbGpWxiFaJyc2cVVo2FbdIZwIxfrX8hSHUIR
oZnJqpHLg//26ZGiVVZ89SGVIRLdcYMCulBzxmhQ7tfDdGuWkHtHEj7eGM8DTEdO
q7u+dhptXArMoWxkVhVJLXU0GjUxjLyH3ftM+YSSil59ML+99qGn3VsCOi2hTB1Q
S34mcSHvJmSV7EoZBa1THcDILdWPGAfA9qv3GdUyMCXVhhse+DvYuO/Iefz7UHG1
/HeHC6yjPR8i/ty76SDwND225yxY2ZLX0qSQ4HtiN5Ks2CzwQl/h15V7HJMpGWFJ
CTKUFQDgefqDzHMIjVK3wGWGiY6vckiK/am/fdxKGFdT2uxMyYxZ4pw6CMR67JMs
0Ey/SBiNAyeqLihSEMri
=OSuc
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]