Here you can find the source of findClassLocation(Class> context)
public static String findClassLocation(Class<?> context) throws IllegalStateException
//package com.java2s; //License from project: Open Source License import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLDecoder; public class Main { public static String findClassLocation(Class<?> context) throws IllegalStateException { String jarRelatedPath = "/" + context.getName().replace(".", "/") + ".class"; URL location = context.getResource(jarRelatedPath); String jarPath = ""; try {//from www. ja va 2 s . com jarPath = URLDecoder.decode(location.getPath(), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } return jarPath.substring(0, jarPath.lastIndexOf("/") + 1); } }