title: ServiceLoader load from different packages
body: <p>I wrote a generic <code>ServiceLocator</code> using the ServiceProviderPattern.</p>
  
  <pre><code>public &lt;T&gt; List&lt;T&gt; locateAll(final Class&lt;T&gt; clazz) {
      final Iterator&lt;T&gt; iterator = ServiceLoader.load(clazz).iterator();
      final List&lt;T&gt; services = new ArrayList&lt;T&gt;();
  
      while (iterator.hasNext()) {
          try {
              services.add(iterator.next());
          } catch (ServiceConfigurationError serviceError) {
              serviceError.printStackTrace(System.err);
          }
      }
  
      return services;
  }
  </code></pre>
  
  <p>It only finds services if I add the service as a dependency to the maven module where the <code>ServiceLocator</code> resists. If this service uses the <code>ServiceLocator</code> itself, I will have a cirular dependency.</p>
  
  <p>I need the <code>ServiceLocator</code> to load classes from not known dependencies.</p>