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