Class JarHell

java.lang.Object
org.elasticsearch.jdk.JarHell

public class JarHell extends Object
Simple check for duplicate class files across the classpath.

This class checks for incompatibilities in the following ways:

  • Checks that class files are not duplicated across jars.
  • Checks any X-Compile-Target-JDK value in the jar manifest is compatible with current JRE
  • Checks any X-Compile-Elasticsearch-Version value in the jar manifest is compatible with the current ES
  • Method Details

    • main

      public static void main(String[] args) throws Exception
      Simple driver class, can be used eg. from builds. Returns non-zero on jar-hell
      Throws:
      Exception
    • checkJarHell

      public static void checkJarHell(Consumer<String> output) throws IOException, URISyntaxException
      Checks the current classpath for duplicate classes
      Parameters:
      output - A String Consumer to which debug output will be sent
      Throws:
      IllegalStateException - if jar hell was found
      IOException
      URISyntaxException
    • parseClassPath

      public static Set<URL> parseClassPath()
      Parses the classpath into an array of URLs
      Returns:
      array of URLs
      Throws:
      IllegalStateException - if the classpath contains empty elements
    • parseModulesAndClassPath

      public static Set<URL> parseModulesAndClassPath()
      Returns a set of URLs that contain artifacts from both the non-JDK boot modules and class path. These URLs constitute the loadable application artifacts in the system class loader.
    • checkJarHell

      public static void checkJarHell(Set<URL> urls, Consumer<String> output) throws URISyntaxException, IOException
      Checks the set of URLs for duplicate classes
      Parameters:
      urls - A set of URLs from the system class loader to be checked for conflicting jars
      output - A String Consumer to which debug output will be sent
      Throws:
      IllegalStateException - if jar hell was found
      URISyntaxException
      IOException
    • checkJavaVersion

      public static void checkJavaVersion(String resource, String targetVersion)
      Checks that the java specification version targetVersion required by resource is compatible with the current installation.