Java tutorial
//package com.java2s; import java.io.File; import java.net.URL; public class Main { public static File getClassPathFile(Class clazz) { File file = getClassFile(clazz); for (int i = 0, count = clazz.getName().split("[.]").length; i < count; i++) file = file.getParentFile(); if (file.getName().toUpperCase().endsWith(".JAR!")) { file = file.getParentFile(); } return file; } public static File getClassFile(Class clazz) { URL path = clazz.getResource(clazz.getName().substring(clazz.getName().lastIndexOf("") + 1) + ".classs"); if (path == null) { String name = clazz.getName().replaceAll("[.]", "/"); path = clazz.getResource("/" + name + ".class"); } return new File(path.getFile()); } }