title: Heroku classpath FileNotFound Exception
body: <p><strong>Context:</strong> I have a Spring Boot application in which I want to send an e-mail to a user after it's account has been created. I have a newUser.html file in my resources folder in which I edit the &quot;e-mail&quot; and &quot;password&quot; field, and a few images that I want to send along. I do this using Jsoup:</p>
  <pre><code>@Override
  public void sendUserCreatedMail(CreateUserRequest createUserRequest) throws MessagingException, IOException {
      //Get JavaMailSender
      JavaMailSenderImpl mailSenderImpl = mailMapper.mapMailSender();
  
      //set the html elements with Jsoup
      Document doc = buildHtmlDocument(Main.class.getClassLoader().getResource(&quot;html/newUser.html&quot;).getPath());
      Element loginElement = doc.getElementById(&quot;login&quot;);
      Element passwordElement = doc.getElementById(&quot;password&quot;);
  
      loginElement.text(&quot;Login: &quot; + createUserRequest.getEmail());
      passwordElement.text(&quot;Password: &quot; + createUserRequest.getPassword());
  
      String html = doc.toString();
  
      // Add inline images, key + value
      Map&lt;String, String&gt; inlineImages = new HashMap&lt;String, String&gt;();
  
      if(Main.class.getClassLoader().getResource(&quot;images/rea-logo-rond.png&quot;).getPath() != null){
          //Get Email images Path
          String logoPath = Main.class.getClassLoader().getResource(&quot;images/rea-logo-rond.png&quot;).getPath();
          inlineImages.put(&quot;logo&quot;, logoPath);
      }
  
      //Create email instance  &amp; send mail
      MimeMessage mimeMessage = mailMapper.mapCreateUserRequestToSender(createUserRequest, inlineImages, html);
      mailSenderImpl.send(mimeMessage);
  }
  </code></pre>
  <p>This all works fine when running the program in my IDE.
  When I run this on Heroku however, I get a &quot;FileNotFound&quot; exception:</p>
  <pre><code>[java.io.FileNotFoundException: file:/app/rea-backend/target/rea-backend-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/html/newUser.html (No such file or directory)]
  </code></pre>
  <p>I have stumbled upon this <a href="https://stackoverflow.com/questions/54292481/heroku-springboot-classpathresource-get-filenotfoundexception">SO Article</a>, but it doesn't have a suitable solution for my case.
  I wish I could just resort to saving the newUser.html as a Blop in my DB, and getting it each time (though it's not really a good work-around..); BUT the way the &quot;Document&quot; constructor works, is it needs a PATH string of the File you are trying to use, not the actual file itself... The same goes for the images that are needed.</p>
  <p>There has to be another way to access the files in your resources folder using Heroku?
  Or am I doing something wrong? I don't understand why it works on local, but not on Heroku.</p>
  <p>Choosing another platform than Heroku is not an option at this point.</p>