Class JarHell


  • public class JarHell
    extends java.lang.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 Summary

      Modifier and Type Method Description
      static void checkJarHell​(java.util.function.Consumer<java.lang.String> output)
      Checks the current classpath for duplicate classes
      static void checkJarHell​(java.util.Set<java.net.URL> urls, java.util.function.Consumer<java.lang.String> output)
      Checks the set of URLs for duplicate classes
      static void checkJavaVersion​(java.lang.String resource, java.lang.String targetVersion)
      Checks that the java specification version targetVersion required by resource is compatible with the current installation.
      static void checkVersionFormat​(java.lang.String targetVersion)  
      static void main​(java.lang.String[] args)
      Simple driver class, can be used eg.
      static java.util.Set<java.net.URL> parseClassPath()
      Parses the classpath into an array of URLs
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • main

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

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

        public static java.util.Set<java.net.URL> parseClassPath()
        Parses the classpath into an array of URLs
        Returns:
        array of URLs
        Throws:
        java.lang.IllegalStateException - if the classpath contains empty elements
      • checkJarHell

        public static void checkJarHell​(java.util.Set<java.net.URL> urls,
                                        java.util.function.Consumer<java.lang.String> output)
                                 throws java.net.URISyntaxException,
                                        java.io.IOException
        Checks the set of URLs for duplicate classes
        Parameters:
        urls - A set of URLs from the classpath to be checked for conflicting jars
        output - A String Consumer to which debug output will be sent
        Throws:
        java.lang.IllegalStateException - if jar hell was found
        java.net.URISyntaxException
        java.io.IOException
      • checkVersionFormat

        public static void checkVersionFormat​(java.lang.String targetVersion)
      • checkJavaVersion

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