Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-548

Loading services (plugins) with the caller's ClassLoader

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Duplicate
    • Icon: Major Major
    • 2.0.4, 2.0.5
    • 1.8.0-beta4
    • Core API
    • None

    Description

      Hi,

      First of all congratulations and thank you for this excellent API.

      I want to use your Slf4j API in my JDBC driver for the Uno LibreOffice / OpenOffice API. I want to use it to redirect loggers from HsqlDB and H2 to the Uno Logger API, but I can't use it without modifying the slf4j-api.jar service loader. Let me explain my problem. 

      Services provider or plugins seem to be loaded in the file:

      LoggerFactory.java

      with the commande:

      ServiceLoader<SLF4JServiceProvider> serviceLoader = ServiceLoader.load(SLF4JServiceProvider.class);
      

      but without ClassLoader who is by default the current Thread's ClassLoader.

      My application, a jar file that embeds the Slf4j API and a service provider for the Uno Logger archives (slf4j-api.jar and UnoLogger.jar), that wants to use Slf4j is loaded by a URLClassLoader by LibreOffice which extend the CLASSPATH and which has as ClassLoader the current Thread's ClassLoader.

      As a result, Services or Plugins can't never see the extended CLASSPATH from my application and never load...
      Would it be possible to load the services with the ClassLoader of the caller:

      ServiceLoader<SLF4JServiceProvider> serviceLoader = ServiceLoader.load(SLF4JServiceProvider.class, LoggerFactory.class.getClassLoader());
      

      instead of that of the current Thread.

      This will allow CLASSPATH inheritance through ClassLoaders... and this is the normal behaviour of

      new Object()
      

      or

      Class.forName()
      

      Thank you.

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            prrvchr pierre
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: