title: Loading static html files using Akka-http Java
body: <p>I've been struggling to get a static file to load from a simple aka-http Java server. I've tried a number of options, but I always get the following error:</p>
  
  <pre><code>[ERROR] [09/07/2018 11:52:06.258] [AkkaRestApiApp-akka.actor.default-dispatcher-4] [akka.actor.ActorSystemImpl(AkkaRestApiApp)] Error during processing of request: 'java.lang.NullPointerException (No error message supplied)'. Completing with 500 Internal Server Error response. To change default exception handling behavior, provide a custom ExceptionHandler.
  java.lang.NullPointerException
  at akka.http.scaladsl.server.directives.FileAndResourceDirectives.$anonfun$getFromResource$1(FileAndResourceDirectives.scala:106)
  ...
  </code></pre>
  
  <p>Here are two examples of the various routes I tried:</p>
  
  <pre><code>return route(path("docs", () -&gt;
          getFromResource("resources/index.html")
        ));
  
  return pathPrefix("docs", () -&gt;
      route(
          pathEnd(() -&gt; getFromResource("resources/index.html"))
  ));
  </code></pre>
  
  <p>The following line correctly prints the path to the file:</p>
  
  <pre><code>try {
         System.out.println(MyDocService.class.getClassLoader().getResource("resources/index.html").toURI());
      } catch (URISyntaxException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  </code></pre>
  
  <p>I assume the path I pass to getFromResource method should be the same. Since the vast majority of akka-http google searches return Scala examples, I'm sure I'm just making some stupid mistake writing a Java version. I found an older StackOverflow post about issues loading static resources when the path contains spaces, so I made sure there are no spaces in the path to my service. Thanks in advance for any pointers.</p>