public static JarFile jarFileOf(Class<?> klass) {
        URL url = klass.getResource(
            "/" + klass.getName().replace('.', '/') + ".class");
        if (url == null)
            return null;
        String s = url.getFile();
        int beginIndex = s.indexOf("file:") + "file:".length();
        int endIndex = s.indexOf(".jar!");
        if (endIndex == -1)
            return null;
        endIndex += ".jar".length();
        String f = s.substring(beginIndex, endIndex);
        File file = new File(f);
        try {
            return file.exists() ? new JarFile(file) : null;
        } catch (IOException e) {
            throw new IllegalStateException(e);
        }
    }
Returns the jar file from which the given class is loaded; or null
if no such jar file can be located.
aws-java-sdk-core/src/main/java/com/amazonaws/util/Classes.java