Here you can find the source of findContainingJar(Class> clazz)
public static String findContainingJar(Class<?> clazz)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.URL; import java.net.URLDecoder; import java.util.Enumeration; public class Main { public static String findContainingJar(Class<?> clazz) { ClassLoader loader = clazz.getClassLoader(); String classFile = clazz.getName().replaceAll("\\.", "/") + ".class"; try {/*ww w .j av a 2 s. com*/ for (final Enumeration<URL> itr = loader.getResources(classFile); itr.hasMoreElements();) { final URL url = itr.nextElement(); if ("jar".equals(url.getProtocol())) { String path = url.getPath(); if (path.startsWith("file:")) { path = path.substring("file:".length()); } path = URLDecoder.decode(path, "UTF-8"); return path.replaceAll("!.*$", ""); } } } catch (IOException e) { throw new RuntimeException(e); } return null; } }