title: How to resolve a Classloader related 'java.lang.LinkageError' when sending email from Tomee?
body: <p>I am trying to send an email from my code that runs on Tomee 1.6</p>
  
  <p>I have the following entry in the tomee.xml file.</p>
  
  <pre><code>    &lt;Resource
      id="abc_mail"
      type="javax.mail.Session"
      &gt;
          mail.transport.protocol=smtp
          mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
          mail.smtp.socketFactory.fallback=false
          mail.smtp.host=smtp.gmail.com
          mail.smtp.port=465
          mail.smtp.auth=true
          mail.smtp.user=xyz@gmail.com
          password=xyzpass
      &lt;/Resource&gt;
  </code></pre>
  
  <p>I have an ejb with the following declaration.</p>
  
  <pre><code>@Resource(name = "abc_mail")//, type = javax.mail.Session.class)
  Session abcMailSession;
  </code></pre>
  
  <p>The code for sending the email is the following.</p>
  
  <pre><code>public void sendMessage(String addressTo, String subject, String messageText) {
          try {
              Message message = new MimeMessage(abcMailSession);
              message.setFrom(new InternetAddress("abc@xyz.com"));
              message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(addressTo));
              message.setSubject(subject);
              message.setText(messageText);
  
              Transport.send(message);
  
              logger.info("Message sent successfully.");
  
          } catch (MessagingException e) {
              throw new RuntimeException(e);
          }
      }
  </code></pre>
  
  <p>When calling this method I get the following error.</p>
  
  <pre><code>Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.geronimo.mail.util.SessionUtil.getBooleanProperty(Ljavax/mail/Session;Ljava/lang/String;Z)Z" the class loader (instance of org/apache/openejb/util/classloader/URLClassLoaderFirst) of the current class, javax/mail/internet/MimeMessage, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/geronimo/mail/util/SessionUtil, have different Class objects for the type vax/mail/Session;Ljava/lang/String;Z)Z used in the signature
  at javax.mail.internet.MimeMessage.isStrictAddressing(MimeMessage.java:1460)
  at javax.mail.internet.MimeMessage.addRecipientsToList(MimeMessage.java:428)
  at javax.mail.internet.MimeMessage.getAllRecipients(MimeMessage.java:400)
  at javax.mail.Transport.send(Transport.java:48)
  at co.uk.dakia.core.interfaces.impl.NotificationManagerImpl.sendMessage(NotificationManagerImpl.java:88)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:182)
  at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:164)
  at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:180)
  at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:99)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:182)
  at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:164)
  at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:80)
  at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:212)
  at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:181)
  at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:268)
  at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:263)
  at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:86)
  at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:303)
  ... 47 more
  </code></pre>
  
  <p><b>Why do I get this error?</b> I am not able to figure out the first line in the stack trace.</p>