title: java.lang.NoClassDefFoundError: Could not initialize class javax.mail.internet.InternetAddress
body: <p>I am trying to send an email using the JavaMail API. Here is my code on the servlet:</p>
  
  <pre><code>package com.lsp.web;
  
  import com.lsp.service.Mailer;
  import javax.ejb.EJB;
  import javax.mail.MessagingException;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import java.io.IOException;
  
  @WebServlet(name = "contact", urlPatterns = {"/contact"})
  public class ContactServlet extends SpringInjectedServlet {
  @EJB
  private Mailer emailBean;
  
  @Override
  public void init() throws ServletException {
  
  }
  
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      doPost(req, resp);
  }
  
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
      String customerEmail = req.getParameter("email");
      String subject = req.getParameter("subject");
      String body = req.getParameter("message");
  
      String error = null;
      String succMess = null;
  
      try {
          javax.mail.internet.InternetAddress ia = new javax.mail.internet.InternetAddress(customerEmail);
          ia.validate();
          emailBean.send(customerEmail, subject, body);
          req.setAttribute("succMessage", succMess);
          req.getRequestDispatcher("sent.jsp").forward(req, resp);
  
      } catch (javax.mail.internet.AddressException ae) {
          error = "您指出的邮箱地址不存在";
          req.setAttribute("errorMessage", error);
          req.getRequestDispatcher("contact.jsp").forward(req, resp);
      }
      catch (MessagingException mex) {
          error = "发送失败";
          req.setAttribute("errorMessage", error);
          req.getRequestDispatcher("contact.jsp").forward(req, resp);
      }
  }
  }
  </code></pre>
  
  <p>At the line where I check for the user address where:</p>
  
  <pre><code>javax.mail.internet.InternetAddress ia = new javax.mail.internet.InternetAddress(customerEmail);
  ia.validate();
  </code></pre>
  
  <p>I got an exception. 
  java.lang.NoClassDefFoundError: Could not initialize class javax.mail.internet.InternetAddress </p>
  
  <p>In pom.xml, I added these lines:</p>
  
  <pre><code>&lt;!--JavaMail API--&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.mail&lt;/groupId&gt;
          &lt;artifactId&gt;javax.mail-api&lt;/artifactId&gt;
          &lt;version&gt;1.5.1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!--EJB--&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.ejb&lt;/groupId&gt;
          &lt;artifactId&gt;ejb-api&lt;/artifactId&gt;
          &lt;version&gt;3.0&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>I am using Tomcat.
  Could someone tell me why this happens and how I can solve the issue.</p>
  
  <p>Thank you. </p>