title: Get context path in Java web application
body: <p>I am trying to get the project context path in Java web application. My project is located in <code>D:\GED\WSysGED</code> directory, I want to get that path. In my research, I found two ways to do this: The first uses <code>System.getProperty</code> like so:</p>
  
  <pre><code>String path= System.getProperty("user.dir");  
  System.out.println(path);
  </code></pre>
  
  <p>But that code returns <code>D:\eclipse-jee-luna-R-win32\eclipse</code>, where the Eclipse executable file is located. </p>
  
  <p>The second way is using a servlet.</p>
  
  <p>I created that one following this
  <a href="http://www.avajava.com/tutorials/lessons/how-do-i-get-the-location-of-my-web-application-context-in-the-file-system.html" rel="nofollow noreferrer">tutorial</a></p>
  
  <pre><code>public class ContextPathServlet extends HttpServlet {
  
  
      private static final long serialVersionUID = 1L;
  
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
  
          ServletContext servletContext = getServletContext();
          String contextPath = servletContext.getRealPath("/");
          PrintWriter out = response.getWriter();
          out.println("&lt;br/&gt;File system context path (in TestServlet): " + contextPath);
      }
  }
  </code></pre>
  
  <p>But it is showing <code>C:\Users\Juan\SysGED\.metadata\.plugins\org.eclipse.wst.server.core\tmp6\wtpwebapps\WSysGED</code> </p>
  
  <p>What is the correct way to get the project path?</p>