title: How to get deploy root directory in servlet based project?
body: <p>I am trying to get deploy root directory of my servlet based project from java. I am using the following lines of codes to get the path details.</p>
  <p>Type 1:</p>
  <pre><code>File directory = new File (&quot;.&quot;);
  try {
      System.out.println (&quot;Current directory's canonical path: &quot; 
              + directory.getCanonicalPath()); 
      System.out.println (&quot;Current directory's absolute  path: &quot; 
                  + directory.getAbsolutePath());
  }catch(Exception e) {
      System.out.println(&quot;Exceptione is =&quot;+e.getMessage());
  }
  </code></pre>
  <p>Type 2:</p>
  <pre><code>String currentDir = System.getProperty(&quot;user.dir&quot;);
  System.out.println(&quot;Current dir using System:&quot; +currentDir);
  </code></pre>
  <p>While executing the above codes from main class i am getting user directory. When i executes from server side, gets as, &quot;Current dir using System:D:\Apache Tomcat 6.0.16\bin&quot;. But my project is located in <code>D:\Apache Tomcat 6.0.16\wepapps\SampleStructs</code>.</p>
  <p>Please give me any suggestions for this and help me out of this.</p>