Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getContextClassLoader() in javax.mail.Session.getService(Provider provider, URLName url)

1045904Oct 7 2013 — edited Oct 8 2013

I am setting up Logback with SMTPAppender for glassfish 4 and having issues with javax.mail.Session's getService(Provider provider, URLName url) method. I have put all the logback jars and javax.mail (javax.mail.jar; jcl-over-slf4j-1.7.5.jar; jul-to-slf4j-1.7.5.jar; logback-classic-1.0.13.jar; logback-core-1.0.13.jar; slf4j-api-1.7.5.jar) in glassfish4\glassfish\lib\endorsed. The getService method, instead of loading the service class by utilizing this.getClass().getClassLoader(), relies on getContextClassLoader(). The service class in my setup is com.sun.mail.smtp.SMTPTransport. Since the javax.mail.Session.class, javax.mail.URLName.class are loaded directly, they resolve to the classes in the endorsed directory. However, the service class is loaded through getContextClassLoader() and it resolves to the class of the jar in glassfish4\glassfish\modules. As a result, the code can't find the constructor:

Class[] c = {javax.mail.Session.class, javax.mail.URLName.class};

Constructor cons = serviceClass.getConstructor(c);

I started to wonder, why the code section below exists in Session.getService(...).

// First try the "application's" class loader.

     ClassLoader ccl = getContextClassLoader();

     if (ccl != null)

  try {

     serviceClass =

  Class.forName(provider.getClassName(), false, ccl);

  } catch (ClassNotFoundException ex) {

     // ignore it

  }

Thanks,

Janos

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 5 2013
Added on Oct 7 2013
2 comments
2,451 views