Created
February 26, 2018 17:00
-
-
Save jaceshim/5bfd4c09009e3fcf14179dfbbeec7e32 to your computer and use it in GitHub Desktop.
Find jar path loaded class in spring controller
This file contains hidden or 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
@Controller | |
public class ClassLoaderController { | |
/** | |
* | |
* @param clazzName 패키지를 포함한 클래스명 ex) javax.servlet.http.HttpServlet | |
* @return | |
*/ | |
@RequestMapping(value = "/find/jar") | |
@ResponseBody | |
public String find(@RequestParam String clazzName) { | |
String result = ""; | |
if (StringUtils.isNoneBlank(clazzName)) { | |
clazzName = clazzName.replace('.', '/').trim(); | |
clazzName = "/" + clazzName + ".class"; | |
java.net.URL classUrl = this.getClass().getResource(clazzName); | |
if (classUrl != null) { | |
String jarFile = classUrl.getFile(); | |
int indexNo = jarFile.indexOf("!"); | |
if (indexNo != -1) { | |
result = jarFile.substring(0, indexNo); | |
} | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment