Created
May 17, 2018 12:30
-
-
Save datacorner/e9fd9cd1ee1cb34b25afd33bc174b574 to your computer and use it in GitHub Desktop.
Returns the real system path of WEB-INF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns the real system path of WEB-INF through a servlet | |
* @return répertoire WEB-INF | |
*/ | |
public static String WEBINF_PATH() { | |
String className = JoyConfigfileProvider.class.getName().replaceAll("\\.", "/") + ".class"; | |
// Use the ClassLoader to find the absolute path to this file. | |
URL classPath = JoyConfigfileProvider.class.getClassLoader().getResource(className); | |
//create a new File and go from file to parent file to find the WEB-INF directory | |
File f = new File(classPath.getPath()); | |
while (f != null && !f.getName().equals("WEB-INF")) | |
f = f.getParentFile(); | |
//if the root is reached without finding the WEB-INF directory WEB-INF will equal null | |
if (f != null) | |
return f.getPath(); | |
else | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment