title: Cant retrieve an images from the WEB-INF folder ussing classLoader.getResourceAsStream()
body: <p>The hold noon i was trying to make my app send both html+images via javamail, i only managed to send html, but with the image i am having a bit of problems. I decided to create a multipart message, and all was going ok, but then i use the class loader to retrieve the .png file from the WEB-INF/resources/images i get a NullPointerExcetion, i dont know why is that?</p>
  
  <p>Here is how my EJB(3.0) looks like. Ill appreciate a hand on this one i dont have much experience with the ClassLoader class(Dont know much about it).</p>
  
  <pre><code>@Stateless(name = "ejbs/EmailServiceEJB")
  public class EmailServiceEJB implements IEmailServiceEJB {
  
  @Resource(name = "mail/myMailSession")
  private Session mailSession;
  
  public void sendAccountActivationLinkToBuyer(String destinationEmail,
          String name) {
  
      // Destination of the email
      String to = destinationEmail;
      String from = "dontreply2thismessage@gmail.com";
  
      try {
          Message message = new MimeMessage(mailSession);
          // From: is our service
          message.setFrom(new InternetAddress(from));
          // To: destination given
          message.setRecipients(Message.RecipientType.TO,
                  InternetAddress.parse(to));
          message.setSubject("Uspijesna registracija");
          // How to found at http://www.rgagnon.com/javadetails/java-0321.html
          message.setContent(generateActivationLinkTemplate(), "text/html");
  
          Date timeStamp = new Date();
          message.setSentDate(timeStamp);
  
          // Prepare a multipart HTML
          Multipart multipart = new MimeMultipart();
          // Prepare the HTML
          BodyPart htmlPart = new MimeBodyPart();
          htmlPart.setContent(generateActivationLinkTemplate(), "text/html");
          multipart.addBodyPart(htmlPart);
          // PREPARE THE IMAGE
          BodyPart imgPart = new MimeBodyPart();
  
          String fileName = "/WEB-INF/resources/images/logoemailtemplate.png";
  
          ClassLoader classLoader = Thread.currentThread()
                  .getContextClassLoader();
          if (classLoader == null) {
              classLoader = this.getClass().getClassLoader();
              if (classLoader == null) {
                  System.out.println("IT IS NULL AGAIN!!!!");
              }
          }
  
  
  
          DataSource ds = new URLDataSource(classLoader.getResource(fileName));
  
          imgPart.setDataHandler(new DataHandler(ds));
          imgPart.setHeader("Content-ID", "the-img-1");
          multipart.addBodyPart(imgPart);
          // Set the message content!
          message.setContent(multipart);
  
          Transport.send(message);
  
      } catch (MessagingException e) {
          throw new RuntimeException(e);
      }
  
  }
  </code></pre>
  
  <p>I would like to mention that i am ussing JEE6 with glassfishV3 i dont know if my approach is compatible with this application server.</p>
  
  <hr>
  
  <p><b>Update</b>
  When i modify the above code to </p>
  
  <pre><code>String fileName = "logoemailtemplate.png";
  </code></pre>
  
  <p>I receive an email, it works.</p>
  
  <p>But now I don't receive the text. :) Is there any mistake?</p>