I have an application deployed on Tomcat server. I used this stackoverflow link to find out the absolute path of the loaded class like below :
Code1:
getClass().getClassLoader().getResource(".").getPath();
Code2:
Thread.currentThread().getContextClassLoader().getResource(".").getPath();
Expected result:
/D:/ProgramFiles/Tomcat-7.0.26/webapps/catalog-web/WEB-INF/classes/
Actual result:
/D:/ProgramFiles/Tomcat-7.0.26/lib/
Was really confused with the result found. Finally I tried below:
Code1:
getClass().getClassLoader().getResource("/").getPath();
Code2:
Thread.currentThread().getContextClassLoader().getResource("/").getPath();
And I finally got my result:
/D:/ProgramFiles/Tomcat-7.0.26/webapps/catalog-web/WEB-INF/classes/
So my question is as below:
a) Can you please explain why this happened ?
b) Also, please tell me if there is any other better way to get my expected result than what I used ?