code: public static File getResourceRoot (final URL url, final String resource)
    {
      String path = null;
      if (url != null)
      {
        final String spec = url.toExternalForm ();
        if ((JAR_FILE).regionMatches (true, 0, spec, 0, JAR_FILE.length ()))
        {
          URL jar;
          try
          {
            jar = new URL (spec.substring (JAR.length (), spec.lastIndexOf ("!/")));
          }
          catch (final MalformedURLException e)
          {
            throw new IllegalArgumentException ("Invalid JAR URL: " + url + ", " + e.getMessage ());
          }
          path = decodeUrl (jar.getPath ());
        }
        else
          if (FILE.regionMatches (true, 0, spec, 0, FILE.length ()))
          {
            path = decodeUrl (url.getPath ());
            path = path.substring (0, path.length () - resource.length ());
          }
          else
          {
            throw new IllegalArgumentException ("Invalid class path URL: " + url);
          }
      }
      return path != null ? new File (path) : null;
    }
docs: Gets the absolute filesystem path to the class path root for the specified
  resource. The root is either a JAR file or a directory with loose class
  files. If the URL does not use a supported protocol, an exception will be
  thrown.
  
  @param url
  The URL to the resource, may be <code>null</code>.
  @param resource
  The name of the resource, must not be <code>null</code>.
  @return The absolute filesystem path to the class path root of the resource
  or <code>null</code> if the input URL was <code>null</code>.