• 2.1.0

Appending ServletContext Manifests to the Registry

This is how Manifests utility class finds all MANIFEST.MF files available in the classpath:

public class Manifests {
  public static void load() {
    // ...
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    Enumeration<URL> resources = loader.getResources("META-INF/MANIFEST.MF");
  }
}

Context ClassLoader of a current Thread is being used to find all available META-INF/MANIFEST.MF files. This mechanism works just fine in web applications (WAR packages) as long as the current thread contains the same class loader as is being used in ServletContext. In some web containers it is not true, and Manifests simply won't see your MANIFEST.MF files.

To solve the problem there is a method append(ServletContext), which allows you to inform Manifests about an additional classloader available. You should call this method in one of your ServletContextListener-s:

public class MyListener implements ServletContextListener {
  @Override
  public void contextInitialized(ServletContextEvent event) {
    Manifests.append(event.getServletContext());
  }
}

You can call append(ServletContext) many times, it's harmless for the registry.