title: java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session
body: <p>I have been receiving this error when trying to run the following code to get a javax.mail.Session object using a tomcat context file.</p>
  
  <pre><code>        Context initCtx = new InitialContext();
          Context envCtx = (Context) initCtx.lookup("java:comp/env");
          Session session = (javax.mail.Session) envCtx.lookup("mail/session");
  </code></pre>
  
  <p>This is the resource declaration in the context.xml.</p>
  
  <pre><code>  &lt;Resource name="mail/Session" auth="Container"
          type="javax.mail.Session"
          mail.smtp.host="host"
          mail.smtp.user="user"
          mail.smtp.password="password"
          mail.smtp.auth="false"/&gt;
  </code></pre>
  
  <p>I understand this can be due to me having the same library for the javax.mail.Session in my application server library(tomcat) folder and in my applications library folder, i have eliminated as many duplicate library files from my application library folder (e.g. mail.jar) that i can see have the javax.mail.Session as part of the library, now i am at a point where i am a still getting this error and not sure what other libraries could be the source of this problem, or is it some other issue that i am not aware of?</p>
  
  <p>What would people suggest i do to find the source of this problem?</p>
  
  <p>Thanks.</p>