title: jUnit loads another Class compared to WebApp runtime
body: <p>I'm working on a feature, where a Cron Job will trigger a connection through javax.mail, and scan all the incoming mails of a certain IMAP account.</p>
  
  <p>It's a part of a Liferay Portlet, built with JSF-2 and Maven, and deployed on a Tomcat server.</p>
  
  <p>I've built a jUnit Test that executes this scenario successfully, running the exact same function that would be called from the the Cron Job. I did this test by executing the <code>maven build package</code> target, and my Maven is using the same JVM with my Tomcat.</p>
  
  <p>But after deploying the WebApp in the server and the Cron Trigger kicks in, I'm getting this error:</p>
  
  <pre><code>    org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger]
      at org.quartz.core.JobRunShell.run(JobRunShell.java:224)
      at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557)
  Caused by: java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
      at javax.mail.Session.initLogger(Session.java:226)
      at javax.mail.Session.&lt;init&gt;(Session.java:210)
      at javax.mail.Session.getDefaultInstance(Session.java:321)
      at javax.mail.Session.getDefaultInstance(Session.java:361)
  </code></pre>
  
  <p>So I guess that under the Tomcat Runtime or Servlet Context or the quartz flow or whatever, there is a different resolution of <code>com/sun/mail/util/MailLogger</code>, compared to the resolution of jUnit. </p>
  
  <p>Why is this happening, and how can I make sure I'm loading the correct Class  in all scenarios?</p>