Here you can find the source of getJarFile(Class clazz)
public static String getJarFile(Class clazz)
//package com.java2s; //License from project: LGPL import java.net.URL; public class Main { public static String getJarFile(Class clazz) { String result = null;/*w w w .j a va 2 s . com*/ if (clazz != null) { String me = clazz.getName().replace(".", "/") + ".class"; URL dirURL = clazz.getClassLoader().getResource(me); if (dirURL.getProtocol().equals("jar")) { result = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); } } return result; } }