code: public static FrameworkFactory getFrameworkFactory(ClassLoader loader) {
          FrameworkFactory factory = null;
          Class<?> factoryClass = null;
  
          final String factoryResource = "META-INF/services/org.osgi.framework.launch.FrameworkFactory";
  
          java.io.InputStream inputstream = loader.getResourceAsStream(factoryResource);
          if (inputstream == null)
              throw new IllegalStateException("Could not find " + factoryResource + " on classpath.");
  
          String factoryClassName = null;
  
          BufferedReader bufferedreader;
          try {
              bufferedreader = new BufferedReader(new InputStreamReader(inputstream, "UTF-8"));
  
              factoryClassName = KernelUtils.getServiceClass(bufferedreader);
              bufferedreader.close();
          } catch (Exception e) {
              throw new IllegalStateException("Could not read FrameworkFactory service: " + factoryClassName + "; exception=" + e);
          }
  
          if (factoryClassName == null)
              throw new IllegalStateException("Could not find FrameworkFactory service: " + factoryResource);
  
          try {
              factoryClass = loader.loadClass(factoryClassName);
  
              Constructor<?> ctor = factoryClass.getConstructor();
              factory = (FrameworkFactory) ctor.newInstance();
          } catch (Exception e) {
              throw new IllegalStateException("Could not load/instantiate framework factory (" + factoryClassName + ")", e);
          } catch (Error e) {
              throw new IllegalStateException("Could not load/instantiate framework factory (" + factoryClassName + ")", e);
          }
  
          return factory;
      }
docs: Use the provided classloader to find the target FrameworkFactory via the
  ServiceLoader pattern. If the
  "META-INF/services/org.osgi.framework.launch.FrameworkFactory" resource
  is found on the classpath, it is read for the first non-comment line
  containing a classname. That factory is then used as the service class
  for creating a FrameworkFactory instance.
  
  @return non-null instance of the framework factory.
  @throws LaunchException
  if Factory can not be found or instantiated.
  @see {@link KernelUtils#getServiceClass(BufferedReader)}