title: ServletContext.getRealPath() returns null on Tomcat 7
body: <p>I had a working Java Web application deployed as a war package in one server and when I moved it to another (both servers using Tomcat 7), I get the following error:</p>
  
  <blockquote>
    <p>HTTP Status 500 - Servlet.init() for servlet amie.demo.AMIEServlet
    threw exception</p>
    
    <p>java.lang.NullPointerException    java.io.File.(File.java:277)
      amie.demo.AMIEServlet.init(AMIEServlet.java:92)</p>
  </blockquote>
  
  <p>The code that causes the problem looks like this:</p>
  
  <pre><code>@Override
  public void init(ServletConfig config) throws ServletException {        
      String kbPath = config.getServletContext().getInitParameter("kb-path");
      String kbAbsPath = config.getServletContext().getRealPath(kbPath);
      String metadataPath = config.getServletContext().getInitParameter("kb-metadata");
      String metadataAbsPath = config.getServletContext().getRealPath(metadataPath);
      try {
          kb.load(new File(kbAbsPath));
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  </code></pre>
  
  <p>The problem is that config.getServletContext().getRealPath is returning null. The property "kb-path" referred in the snippet is defined in the web.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt;
    &lt;display-name&gt;AMIEDemo&lt;/display-name&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;context-param&gt;
      &lt;param-name&gt;kb-path&lt;/param-name&gt;
      &lt;param-value&gt;yago2core.10kseedsSample.decoded.compressed.notypes.nolangcode.usascii.tsv&lt;/param-value&gt;
    &lt;/context-param&gt;  
    &lt;context-param&gt;
      &lt;param-name&gt;kb-metadata&lt;/param-name&gt;
      &lt;param-value&gt;yagoWikipediaInfo.relevance.sample.tsv&lt;/param-value&gt;
    &lt;/context-param&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>The file referenced by the "kb-path" property is located at the root of the .war package. As I said, this worked in the previous server, so I suspect there is a configuration issue. Any hint will be highly appreciated. </p>